-2

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.

Daniel Santos
  • 405
  • 4
  • 13

1 Answers1

4

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.

Robert Harvey
  • 198,589
  • 55
  • 464
  • 673