How to Use EF Core 2.2.4 Data Library With Asp.Net Core 2.1 Project

asp.net-core c# entity-framework-core

Question

I am trying to create a new Restful web api using Asp.Net Core 2.1 and I would like to use a shared data library to access the underlying data. The data library uses Entity Framework Core 2.2.4 and entity framework 6.1

There are other applications that reference this data library and it would be beneficial to have the web api also referencing the same project.

As soon as I add any code that references the dbContext I get the following error when trying to compile the web api:

Assembly 'data' with identity 'data uses 'Microsoft.EntityFrameworkCore, Version=2.2.4.0 which has a higher version than referenced assembly 'Microsoft.EntityFrameworkCore' with identity 'Microsoft.EntityFrameworkCore, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

Is what I'm trying to do even possible and if so can you please point me in the right direction

1
1
5/21/2019 11:38:53 AM

Accepted Answer

The version of EF Core is tightly coupled with the version of ASP.NET Core you're using. Basically: EF Core 2.2.x only works on ASP.NET Core 2.2.x. You'll need to update the TargetFramework to netcoreapp2.2 to make it work.

Also, the recommended way to reference ASP.NET Core (in .NET Core 2.x projects) is to not include a specific version:

<PackageReference Include="Microsoft.AspNetCore.App" />

Instead of

<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
1
5/21/2019 11:55:22 AM


Related Questions





Related

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