LINQPad 与 EF Core 8.0 程序集的连接失败。数据库提供程序不支持 HierarchyId 类型

问题描述 投票:0回答:1

使用内置 Entity Framework Core 8.0 驱动程序连接 LINQPad 失败并出现 InvalidOperationException: 无法映射“HierarchyId”属性“domainObject.Property”,因为数据库提供程序不支持此类型。考虑使用值转换器将属性值转换为数据库支持的类型。请参阅 https://aka.ms/efcore-docs-value-converters 了解更多信息。或者,使用“[NotMapped]”属性或使用“OnModelCreating”中的“EntityTypeBuilder.Ignore”从模型中排除该属性。”

虽然我得到这是返回到 LINQPad 的错误,但程序集工作正常并返回 HierarchyId 对象,在我的应用程序中没有问题。

已升级到 EF8 和 LINQPadd8,因此应该本机支持 HierarchyId(正如我的应用程序中所示)。

entity-framework-core linqpad hierarchyid
1个回答
0
投票

对于登陆这里的其他人... 我正在传递使用 Program.cs 中的 HierarchyId 的选项。

// Add services to the container.
builder.Services.AddDbContext<TempDbContext>(options =>
    options.UseSqlServer(builder.Configuration.GetConnectionString("MyDB"), x => x.UseHierarchyId()), ServiceLifetime.Scoped);

显然这没有包含在我尝试在 Linqpad 中使用的程序集中。

我应该做的是通过 DbContect 的 OnConfiguring 方法添加该选项。这解决了我的问题。

protected override void OnConfiguring(DbContextOptionsBuilder options)
{
    options.UseSqlServer(conf =>
    {
        conf.UseHierarchyId();
    });
}

因此,虽然程序集在我的应用程序中工作,但这只是因为在构造时传入了 UseHierarchyId 选项。

© www.soinside.com 2019 - 2024. All rights reserved.