Open mary-georgiou-sonarsource opened 2 months ago
I noticed a test has been created for this, but it hasn't yet been fixed. Is this likely to be fixed soon as we are having to supress this error.
I think not only EF Entity Ids. When desiging an Entity in EF you may want to have any other property that is filled from a database column that is set from outside the application and should not be changed in the code.
And not only EF, you may want to desserialize a JSON into a class object that should not allow setting properties in the code. The serializer needs the private setters.
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:
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
Expected behavior
It should not raise for properties on classes representing entities in EF core that have unused private setters.