MapToStoredProcedures not available entity-framework-6 entity-framework-core


I saw a few questions related to this on stack overflow but none of them helped. I am using VS 2019 community edition, I created an API project on .NetCore 2.1, and added the following nuget packages. (assuming all EF packages will be included by default)

  1. Microsoft.EntityFrameworkCore.SqlServer

  2. Microsoft.EntityFrameworkCore.Design

After some time into the coding I needed to use MapToStoredProcedures in the OnModelCreating function..But its not available,

entitytypebuilder doesnot contain a definition for maptostoredprocedures

after looking for a few solutions, i tried to

install-package Microsoft.EntityFrameworkCore.Relational

which did not work as there was a version conflict issue...

NU1202: Package Microsoft.EntityFrameworkCore.Relational 3.0.0 is not compatible with netcoreapp2.1 (.NETCoreApp,Version=v2.1).

then i tried to install SDK and restart VS, then i again tried to install Microsoft.EntityFrameworkCore.Relational nuget package but the same error was there.

Finally, I installed:

Microsoft.EntityFramework (6.3) and an older version of Microsoft.EntityFrameworkCore.Relational (2.1.11)

which was successful but the MapToStoredProcedures function is still unavailable.

the using statement in the class also doesnt show Microsoft.EntityFrameworkCore.Relational namespace...

I am very confused as this function used to be available in VS 2013 with EF 6. :S

10/7/2019 5:42:54 AM

Accepted Answer

So i realize that EF 6 used to have the MapToStoredProcedures function and EF Core doesn't have it. (Not sure why they decided like that).

I changed my target framework to netcoreapp3.0 from netcoreapp2.1 and then i was able to install Tools and Microsoft.EntityFrameworkCore.Relational packages.

Finally, I am calling my sp as follows:

var dbResults = _gecontext.ParameterDetails.FromSqlRaw("EXEC dbo.get_nextParamSummary @UserId={0}", userId).ToList();
10/21/2019 2:32:22 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow