我正在将项目从
.NET Core 2.1
升级到 .NET 8
,作为其中的一部分,我还需要将 Entity Framework Core
升级到 8.0。
在其中一个代码行中,使用了“With”方法,但该方法不可在 EF Core 8.0 中使用,因此,我收到错误。
那么,有什么替代方法可以使用吗?
我试图从 EF Core 文档中找到替代方法,但找不到。
使用语句:
使用 System.Data.Common;
使用System.Data.SqlClient;
使用 Microsoft.EntityFrameworkCore;
使用 Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal;
使用 Microsoft.EntityFrameworkCore.Storage;
发生错误的代码:
var contextOptions = new DbContextOptionsBuilder()
.UseSqlServerForAzure(
connectionStringBuilder.ConnectionString,
b => b.CommandTimeout(CommandTimeout ?? DefaultMasterConnectionCommandTimeout))
.Options;
return new AzureSqlMsiRelationalConnection(Dependencies.With(contextOptions));
您应该使用 与表达式
new AzureSqlMsiRelationalConnection(Dependencies with { ContextOptions = contextOptions });