Open
Description
Description
In EF Core, once properties are being set via the constructor, it can make sense to make some of them read-only. EF Core supports this, but there are some things to look out for:
- Properties without setters are not mapped by convention. (Doing so tends to map properties that should not be mapped, such as computed properties.)
- Using automatically generated key values requires a key property that is read-write, since the key value needs to be set by the key generator when inserting new entities.
An easy way to avoid these things is to use private setters.
Although the setters seem unused, in reality, EF Core is using the field in an extralinguistic manner.
See MSDN docs for more information.
Repro steps
public class Blog
{
public Blog(int id, string name,)
{
Name = name;
}
public int Id { get; private set; } // FP
public string Name { get; private set; }
}
Expected behavior
It should not raise for properties on classes representing entities in EF core that have unused private setters.
Activity