Oliver
Oliver

Reputation: 193

Stored Procedures and Entity Framework 5

I'm using Entity Framework 5, and I reverse engineer code first the database I'm using, and then I added an ADO.NET Entity Data Model so that I can use Stored Procedures as reverse engineer code first didn't provide the use of sprocs. Is this the only way to access sprocs?

Also, I realize that after the reverse engineer code first process is done a bunch of classes (tables from the database) are created but as soon as I add the ADO.NET Entity Data Model, most of the classes go away. Does anybody know why?

Upvotes: 1

Views: 6020

Answers (3)

Zylv3r
Zylv3r

Reputation: 21

There is a pattern that you can follow to create or support store procedures with the code first approach. here is a link that you can use to follow this:

http://www.codeproject.com/Articles/179481/Code-First-Stored-Procedures

In few words you need to do the same that you do with model first, create a class that supports the inputs and a class that supports the result set.

And about the Data Entity Model and missing classes. You need to consider that you only can have one approach in a project: code first/(model first/database first), so this could be the reason why you are not seeing those clases.

Upvotes: 1

John Liu
John Liu

Reputation: 186

You can use Context.Database.SqlQuery to run SP.

Upvotes: 0

Related Questions