Dealing with IReadOnlyCollection property in Entiry Framework Core 2.1

后端 未结 1 1068
名媛妹妹
名媛妹妹 2020-12-31 17:31

I\'ve got the following domain entity:

public string Reference { get; private set; }
public int SupplierId { get; private set; }
public int BranchId { get; p         


        
1条回答
  •  执笔经年
    2020-12-31 18:04

    It's possible to configure a backing field usage for a navigation property, but not via Property method which is for primitive property, and not via fluent API (doesn't exist at this time), but directly through mutable model metadata associated with the relationship:

    modelBuilder.Entity()
        .HasMany(e => e.LineItems)
        .WithOne(e => e.PurchaseOrder) // or `WithOne() in case there is no inverse navigation property
        .Metadata.PrincipalToDependent.SetPropertyAccessMode(PropertyAccessMode.Field); // <--
    

    You can also set the mode for all entity navigation properties (you can still override it for individual properties) by using:

    modelBuilder.Entity()
        .Metadata.SetNavigationAccessMode(PropertyAccessMode.Field);
    

    0 讨论(0)
提交回复
热议问题