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

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

Accepted Answer

I did some research as this topic provided some fresh perspectives, and Marc's response was helpful. Basically Understanding EF Code First off, since you have to create the database first, insert data into it, and then select what is there (which makes more sense), it is kind of impossible to create an SP for Select when you have no database. Instead, you must create the stored procedure in SQL and use the following code to run it: A stored procedure may be used in yourDbContext as follows: class.

this.Database.SqlQuery<YourEntityType>("storedProcedure‌​Name",params);

Both @Marc S and Source deserve credit.

2
12/24/2016 3:04:54 PM


Related Questions





Related

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