There are a few different ways to execute a Stored Procedure through a C# application, each of them following different principles. One of the most used approach is to use an SqlCommand object of type CommandType.StoredProcedure and invoke it's ExecuteReader() function. Entity Framework though, allows you to implicitly or explicitly execute a Stored Procedure through it's entities. The reason why I said implicitly or explicitly has to do with the way you will eventually execute the stored procedure. Let me explain a little farther about this. Suppose you have a DbContext Model class generated from your database and you have a table named "Products". You also have created 4 stored procedures, the GetAllProducts, InsertNewProduct, UpdateProduct and DeleteProduct. Those stored procedures can be executed in two different ways with Entity Framework. You can "bind" the GetAllProducts stored procedure which is a select statement, directly to you DbContext class so you can execute it writting something like this:


I guess you came to this post by searching similar kind of issues in any of the search engine and hope that this resolved your problem. If you find this tips useful, just drop a line below and share the link to others and who knows they might find it useful too.

Stay tuned to my blogtwitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.


This article is related to

C#,.NET,Architect,Intermediate,VS2012,.Net,Articles,Computer Tutorials,Entity Framework