EF 6 Code First From Database - Calling existing stored procedure

degmo

I am using EF 6 to connect to an existing SQL database. I want to generate a model for some existing entities and non-CRUD stored procedures. From visual studio, I am adding a new "ADO.NET Entity Data Model" and selecting "Code First from Database" for the model content. However, the only database objects that are available to me are Tables and Views. Stored procedures aren't available. Is this by design or am i missing something here?

Francisco Goldenstein

You need to define a DTO for each stored procedure. You just create simple classes where the propery names of the classes match the name of the columns that are returned by the stored procedure. So, when you call the Stored Procedure from EF, your objects are built and populated. The performance is great! Here I'm pasting an example:

dbContext.Database.CommandTimeout = 3600;
List<CarsDTO> objs = dbContext.Database.SqlQuery<CarsDTO>(
         "spGetCars @carMakeId", new SqlParameter("carMakeId", id)
).ToList();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

EF 6 DataBase First Stored Procedure

Calling Stored Procedure from EF 6.0 Code First doesn't insert records

How to retrieve output parameter from stored procedure by EF code first

How to create a stored procedure from EF Core code first approach?

Stored procedure in mvc using EF(Database first)

How to delete and recreate from scratch an existing EF Code First database

Updating EF entities that are "code first from an existing database"

EF Code First with existing database on another database

EF6 code first: passing a parameter to a mapped delete stored procedure

Alter Stored Procedure in DB Migration EF 6 Code First - how to pass through null as default for a parameter

Calling existing Stored procedure using Entity Framework 6 with C#

Stored procedure visible in EF6 model browser, but can't call it from code

How to execute stored procedure from Entity Framework 6 (database first) and Npgsql?

Adding a table to an existing Database code first MVC 5 EF6

How to use DbContext.Database.SqlQuery<TElement>(sql, params) with stored procedure? EF Code First CTP5

Calling a stored procedure from another stored procedure

How to add additional tables to an existing code first from database EF model?

EF 6 database first: How to update stored procedures?

¿How to call existing stored procedure in oracle by EF?

Calling a simple stored procedure in EF core 3.1

Calling an API from a stored procedure

Entity framework - Return GUID from database first stored procedure

Why is it called 'Code First' from database in EF

Call stored procedure from Entity Framework 6.1.3 code-first

Entity Framework 6 Code First From Database context performs CREATE TABLE on existing an VIEW

Influencing how entity classes are created in EF 6 code-first from database

How to call Stored Procedure from App_Code DataBase Class

EF 6 - Stored Procedure Duplicate Result Column

calling stored procedure in Entity framework database first - Column generation issue in result class