如何将Azure函数V3与实体框架6一起使用(异常System.Data.SqlClient:SystemData.Sq



我有一个Azure V3应用程序,它必须调用基于Entity Framework 6.4构建的DAL repos在数据库初始化时,我得到一个异常:

System.Data.SqlClient:SystemData.SqlClient在此平台上不受支持

来自:System.Data.SqlClient4.8

public sealed partial class SqlConnection : System.Data.Common.DbConnection, System.ICloneable
{
public SqlConnection() 
{ 
throw new System.PlatformNotSupportedException(System.SR.PlatformNotSupported_DataSqlClient)
}
}

在类似的线程中,解决方案是将System.Data.SqlClient降级到4.5.1版本,但在我的情况下,依赖项是由实体框架添加的。

有人知道是否可以在Azure功能V3应用程序中使用实体框架6.4吗?

它似乎仍然是一个.NET Core 3.0 SDK错误,下面是您可以参考的解决方法。

右键单击Function项目并编辑<FunctionAppName>.csproj,在下面添加项目以将相关程序集复制到输出目录。

<ItemGroup>
<None Include="$(USERPROFILE).nugetpackagessystem.data.sqlclient4.6.0runtimeswinlibnetcoreapp2.1System.Data.SqlClient.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

如果你想继续使用.NET Core 3.0 SDK,或者需要对函数v3进行修复:

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<!-- https://github.com/Azure/azure-functions-host/issues/3568#issuecomment-461182536 -->
<Exec Command="copy $(OutDir)$(ProjectName).deps.json $(OutDir)binfunction.deps.json" />
</Target>
<Target Name="PostPublish" BeforeTargets="Publish">
<!-- https://github.com/Azure/azure-functions-host/issues/3568#issuecomment-461182536 -->
<Exec Command="copy $(PublishDir)$(ProjectName).deps.json $(PublishDir)binfunction.deps.json" />
<!-- https://github.com/Azure/azure-functions-vs-build-sdk/issues/333 -->
<Exec Command="move $(PublishDir)runtimes $(PublishDir)bin" />
</Target>

相关内容

最新更新