Efcore: Use the correct MemberInfo for collection include

Created on 26 Jun 2019  路  2Comments  路  Source: dotnet/efcore

Usually this should be navigation.GetMemberInfo(forConstruction: true, forSet: true)

closed-fixed type-bug

Most helpful comment

Something like

```C#
modelbuilder.Entity().SetNavigationAccessMode(PropertyAccessMode.Field);

```C#
private class CoolEntity
{
    private ICollection<CoolEntity> _otherEntities;

    public int Id { get; set;}
    public ICollection<CoolEntity> OtherEntities
    {
        get => _otherEntities;
        set => throw new InvalidOperationException();
    }
}

This applies to all collections populated directly from query.

All 2 comments

@AndriySvyryd - How should I construct my model to add a regression test for this? Is this only applicable to collection include (as opposed to naked collection navigation projection)?

Something like

```C#
modelbuilder.Entity().SetNavigationAccessMode(PropertyAccessMode.Field);

```C#
private class CoolEntity
{
    private ICollection<CoolEntity> _otherEntities;

    public int Id { get; set;}
    public ICollection<CoolEntity> OtherEntities
    {
        get => _otherEntities;
        set => throw new InvalidOperationException();
    }
}

This applies to all collections populated directly from query.

Was this page helpful?
0 / 5 - 0 ratings