Monzir
Monzir

Reputation: 621

How to use stored procedures in Entity Framework 6-database first?

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.

Upvotes: 1

Views: 2780

Answers (1)

Ismapro
Ismapro

Reputation: 120

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

Upvotes: 1

Related Questions