How to MAP select stored procedure in Entity Framework 6 code-first approach?

c# ef-code-first entity-framework entity-framework-6 stored-procedures


For example when we write

protected override void OnModelCreating(DbModelBuilder modelBuilder)

Then it will create 3 stored procedures in the database with the names of tblError_Delete, tblError_Insert, tblError_Update

My question is about tblError_Select: how to map a stored procedure that is used to execute select queries?

I want EF to be generate tblError_Select along with preceding 3 stored procedures.

I want to do CRUD operation using stored procedures with EF. Currently I can do Insert, Update, Delete but what about Select? Why does EF not create a stored procedure for Select operation?

12/24/2016 12:29:10 PM

Accepted Answer

Since this question brought some new insights, I've researched a little and marc_s answered helped. Basically Knowing EF Code-First, when you do not have any database it is kinda impossible to create a SP for Select, since you have to create the database first then insert data within then select what is there (which makes more sense), you have to create the Stored Procedure within the SQL and use code below to run it: You can call a stored procedure in your DbContext class as follows.


Credit goes to @Marc_S and Source

12/24/2016 3:04:54 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow