I want to know how to send parameters to stored procedure from entity framework? Thanks in advance.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First question is: for which version of the Entity Framework?? .NET 3.5? .NET 4 ?? Things have significantly changed (and improved!) in .NET 4.
And secondly: what do you want to do:
retrieve rows from the database
execute a stored proc without return value
map INSERT/UPDATE/DELETE operations on an entity to a stored proc??
These are three pretty different scenarios – so we need to know what you’re going for.
Also: just search with Google (or Bing) – there are plenty of blog post and tutorials out there showing you how to do it – a quick list:
and literally thousands more ……
Update: ok, so you want to retrieve data from the database. In that case, your steps are:
Update Model from DatabaseThis creates an entry for the stored procedure in your physical storage model. Next:
Model Browser(see the above context menu? It’s just belowUpdate Model from Database), navigate to the Storage Model and find your procedureAdd Function Importwhich imports the “function” (stored procedure) from the physical storage model into the conceptual model (your entity context class, basically).Here, you have four choices:
Customerentities – in that case, select the last option and pick the entity you want to map to (your stored proc must return all columns for that entity, in this case)OR:
Whichever you do – basically EF will create a method on your object context class that you can call. Any parameters your stored proc requires will be parameters of that method so you can very easily pass in e.g. strings, ints etc.