Skip to content

Scaffolded collection navigation properties do not have setters #30286

@giarico

Description

@giarico

Hello,

With EF7 all child entities are get only collections.
If I use the generated entities for deserialization, the child entities remain null.

Example of an entity with a child collection. Before EF7 it was get & set.

public partial class ComplaintType
{
    ...

    [InverseProperty("ComplaintType")]
    public virtual ICollection<LocalizedComplaintType> LocalizedComplaintTypes { get; } = new List<LocalizedComplaintType>();
}

When I try to deserialize the returned json to the ComplaintType object, the LocalizedComplaintTypes property is null
return await httpClient.GetFromJsonAsync<IEnumerable<ComplaintType>>(...);

If I modify the ComplaintType class putting set or init on LocalizedComplaintTypes property, it works.

Why this change in EF7? I had a lot of drawbacks... and not limited to this.
What is the workaround?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions