GLuca74
GLuca74

Reputation: 135

EF Core - Navigations and Property Bag

EF Core support Navigations on Property Bag Entity or Navigation on Entity that points to a Property Bag Entity?

Having this class

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

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

I tried this :

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();
}

or this :

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);
    });
}

both returns

The navigation 'Details' cannot be added to the entity type PropertyBagEntity (Dictionary<string, object>) because there is no corresponding CLR property on the underlying type and navigations properties cannot be added in shadow state.

is there a way to achive?

Upvotes: 3

Views: 899

Answers (0)

Related Questions