[英]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.我共享了使用实体框架 6.4 的项目,它代表其他项目中使用 .net 框架 4.7.2 的数据访问层。
I also have created an azure function version 2 project.我还创建了一个 azure function 版本 2 项目。 The framework is .net standard 2.0 which supports .net core 2, as it is needed for azure functions.
该框架是 .net 标准 2.0,它支持 .net 核心 2,因为它是 azure 功能所必需的。
The problem happens when I want to use that shared entity framework project in azure function.当我想在 azure function 中使用该共享实体框架项目时,就会出现问题。 Since EntityFramework 6.4 is not supported on .net standard 2.0
由于 .net 标准 2.0 不支持 EntityFramework 6.4
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.我正在寻找升级或降级甚至框架更改的解决方案,以在 azure function 和所有其他项目中使用该共享实体框架项目。
Entity Framework 6.4 is compatible with netstandard 2.1, but not 2.0, meaning it requires dotnet core 3.0 at minimum. Entity Framework 6.4 与 netstandard 2.1 兼容,但不兼容 2.0,这意味着它至少需要 dotnet core 3.0。
But if you can upgrade your azure function project to target core 3.0, you can enable multi-targeting in your data layer project.但是,如果您可以将 azure function 项目升级到目标核心 3.0,则可以在数据层项目中启用多目标。
Open the csproj
file and replace:打开
csproj
文件并替换:
<TargetFramework>netstandard2.0</TargetFramework>
by经过
<TargetFrameworks>netstandard2.1;net472</TargetFrameworks>
Note the change from TargetFramework
to TargetFrameworks
, this is important!注意从
TargetFramework
到TargetFrameworks
的变化,这很重要!
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.这将使项目能够被针对完整框架(4.7.2 及更高版本)的项目以及网络标准 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.如果您使用 v1 版本的 Azure 函数,则兼容性问题较少,例如支持 EF,但您可能仍会遇到其他依赖项的问题。
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.过去,我通过创建 V2 函数获得了巨大的成功,这些函数充当“前端”,将消息发布到事件中心或服务总线队列。 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.
然后使用连续的 web 作业来处理 .net 框架代码中的这些排队消息,我现在将其称为解决方案的“遗留”部分。
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 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? @Aryan 你有没有解决过这个问题? 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?
如果您的共享数据库的目标是 .net 框架 4.7.2(netStandard 2.0),那么您的 Azure ZC1C425268E68385D1AB5074C17A904F14 是否与共享库兼容? This can happen if your data library is targeting .net framework 4.5?
如果您的数据库针对 .net 框架 4.5,可能会发生这种情况? EF 6.4 actually targets net standard 2.1 or .net framework 4.5.
EF 6.4 实际上以网络标准 2.1 或 .net 框架 4.5 为目标。 Thoughts?
想法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.