Is it true that you cannot call an sp with the EF unless the sp returns an entity?
To test I created 3 Function Imports for an sp with 1. no return type 2. a scalar return type and 3. an entity return type
then when i type "DataContext" then "." I only get intellisense on the function that returns an entity!
I'm surprised this isn't a current feature!
What are people using as a workaround?
Entity Framework has the ability to automatically build native commands for the database based on your LINQ-to-Entities or Entity SQL queries, as well as build the commands for inserting, updating, and deleting data. You may want to override these steps and use your own predefined stored procedures.
You can execute SP using FromSql method in EF Core in the same way as above, as shown below.
The support for stored procedure in EF Core is similar to the earlier versions of EF Code first. You need to create your DbContext class by inherting the DbContext class from EF. The stored procedures are executing using the DbContext. First step is to write a method that create a DbCommand from the DbContext.
There is a workaround!
Julie Lerman wrote a post about this. Have a look at her blog: http://thedatafarm.com/blog/data-access/implement-select-stored-procedures-that-return-miscellaneous-data-in-ctp2-of-ef-designer/
It helped me a lot to implement my stored procedures.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With