EF Core - 导航和属性包

时间:2021-05-24 10:53:03

标签: c# entity-framework-core propertybag

EF Core 支持属性包实体上的导航还是指向属性包实体的实体上的导航?

有这门课

public class PropertyBagEntityDetail
{
    public string StringProperty { get; set; }

    public Dictionary<string, object> Parent { get; set; }
}

我试过了:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
           modelBuilder.SharedTypeEntity<Dictionary<string, object>>("PropertyBagEntity", bb =>
            {
                bb.Property<int>("IntProperty");
                bb.Property<string>("StringProperty");
                bb.Property<DateTime>("DateTimeProperty");
            });

            modelBuilder.Entity<PropertyBagEntityDetail>().HasOne(itm => itm.Parent).WithMany();
}

或者这个:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
 
             modelBuilder.SharedTypeEntity<Dictionary<string, object>>("PropertyBagEntity", bb =>
            {
                bb.Property<int>("IntProperty");
                bb.Property<string>("StringProperty");
                bb.Property<DateTime>("DateTimeProperty");
                bb.HasMany<PropertyBagEntityDetail>("Details").WithOne(itm=>itm.Parent);
            });

 
}

两者都返回

无法将导航“详细信息”添加到实体类型“PropertyBagEntity (Dictionary)”,因为基础类型上没有对应的 CLR 属性,并且无法在阴影状态下添加导航属性。

有什么方法可以实现吗?

0 个答案:

没有答案