1

I have an already existing database and i generated my ".edmx" file from the database. After that i added the stored procedure via update model from database menu and in the model browser i can see my procedure name and complex type but i can't see the complex type in the "IntelliSense".

dbContext.Database.SqlQuery<mycomplextype>

IntelliSense doesn't show the complex type when i write thecode to call the stored procedure. I didn't see anything related to the stored procedure in the context class either.

What is the proper way to add and use stored procedure in entity framework database first? Can anyone point out what i am missing?

Thank you.

Edit:

dbcontext.storedprocedurename

I can't see my stored procedures name in this way but the edmx shows the procedure in the function imports section in model browser.

6
  • Do you see the stored procedure and its return type in the Model browser? How did you call the procedure? What type does Intellisense show when for this stored procedure? The method you posted isn't used to call stored procedures, it's used to run ad-hoc queries Commented Jun 8, 2015 at 13:56
  • Dbcontext.StoredProcedureName(...) this doesn't work because i cant see my procedures name after Dbcontext. Commented Jun 9, 2015 at 6:54
  • Have you added it at all? Do you see it in the Model Browser? Please post your code - especially the line where you instantiate the context. If you don't see the stored procedure, you probably never added it when creating the model Commented Jun 9, 2015 at 6:56
  • using (WEB_DATA_DBEntities dbContext = new WEB_DATA_DBEntities()) { dbContext..... } ...... i added it in the model. the stored procedure name is in the function imports. Commented Jun 9, 2015 at 6:59
  • And is the stored procedure available in the model browser? Commented Jun 9, 2015 at 6:59

1 Answer 1

1

I got 6.1.3 EntityFramework version and I am using Database First approach.

To use my stored procedure i added it to the Model with the helper it is reference as a method and call it like so in query

Dbcontext.StoredProcedureName(prop1,prop2,..); Dbcontext.SaveChangesAsync();
Sign up to request clarification or add additional context in comments.

3 Comments

can explain the helper thing please?
@Answer_42 probably means the model wizard. In a Model First approach, the wizard allows you to select both stored procedures and tables. If you do this, you can call the stored procedure with eg myContextInstance.MyProcedure(x,y)
Yes I meant the wizard . It allows you to add table or views but also stored procedures

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.