Quantcast
Channel: Development With A Dot
Viewing all articles
Browse latest Browse all 404

Entity Framework Pitfalls: Non Public Entity Sets Setter

$
0
0

When defining your entity sets in a Code First context (DbContext), you declare your entity sets as properties of the DbSet<T> type. Weird as it may seem, these properties need to be declared with both a public getter and setter. It really doesn’t make much sense, because you wouldn’t want to set these properties from outside the context, but that’s how it is. So, this won’t work:

   1:public DbSet<Product> Products { get; protected set; }

While this does:

   1:public DbSet<Product> Products { get; set; }
Don’t ask me why! Winking smile

Viewing all articles
Browse latest Browse all 404

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>