Why C# ASP.NET MVC Code First POCO Classes must have getters and setters?
https://softwareengineering.stackexchange.com/questions/325700
-
22-12-2020 - |
Question
Why in, C# ASP.NET MVC Code First project, POCO Classes must have getters and setters ( {get; set; } ) in order to work?
public float data { get; set; }
or in db context class
public DbSet<SGD.Models.MyData> MyData{ get; set; }
I just don't understand why a simple attribute (without getters and setters) doesn't works.
Solution
Because Microsoft decided to only support properties in Entity Framework.
There are many reasons why properties are preferred over public fields, but I'll just mention the one that I think is most relevant here: changing from public fields to properties (if the need arises) is a binary breaking change.
Licensed under: CC-BY-SA with attribution
Not affiliated with softwareengineering.stackexchange