1
votes

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.

1
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 - Panagiotis Kanavos
Dbcontext.StoredProcedureName(...) this doesn't work because i cant see my procedures name after Dbcontext. - Monzir
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 - Panagiotis Kanavos
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. - Monzir
And is the stored procedure available in the model browser? - Panagiotis Kanavos

1 Answers

1
votes

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();