简体   繁体   中英

EntityFramwork compatibility with .net framework 4.7.2 projects and .net standard 2.0 project

I have shared project that use entity framework 6.4 and it represents data access layer in other projects with .net framework 4.7.2.

I also have created an azure function version 2 project. The framework is .net standard 2.0 which supports .net core 2, as it is needed for azure functions.

The problem happens when I want to use that shared entity framework project in azure function. Since EntityFramework 6.4 is not supported on .net standard 2.0

I am looking for a solution to upgrade or downgrade or even framework change to use that shared entity framework project in azure function and all other projects.

Entity Framework 6.4 is compatible with netstandard 2.1, but not 2.0, meaning it requires dotnet core 3.0 at minimum.

But if you can upgrade your azure function project to target core 3.0, you can enable multi-targeting in your data layer project.

Open the csproj file and replace:

<TargetFramework>netstandard2.0</TargetFramework>

by

<TargetFrameworks>netstandard2.1;net472</TargetFrameworks>

Note the change from TargetFramework to TargetFrameworks , this is important!

This will enable the project to be referenced by projects targeting the full framework (4.7.2 and above) as well as anything supported by net standard 2.1.

If you use v1 version of Azure Functions there are less compatibility issues, EF for instance is supported but you might still run into issues with other dependencies.

I have had great success in the past by creating V2 functions that operate as a "front end" that post messages to Event Hubs or a Service bus Queue. Then use a continuous web job to process these queued messages in .net framework code, which I now refer to as the "legacy" portion of my solution.

Another option is to use a REST API that runs in .net fx, this will keep your functions lightweight as they only need to call endpoints in the API

@Aryan did you ever solve this problem? If your shared data library is targeting .net framework 4.7.2(netStandard 2.0) then won't your Azure function (netStandard2.0) be compatible with shared library anyway? This can happen if your data library is targeting .net framework 4.5? EF 6.4 actually targets net standard 2.1 or .net framework 4.5. Thoughts?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM