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?
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.
Comments