Quantcast
Channel: entityframework Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1793

New Post: Accessibility of DbSet properties misunderstanding

$
0
0
I have created simple context class:
class BonusContext : DbContext
{
    public DbSet<ActCategory> ActCategories { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Configurations.Add(new ActCategoryConfiguration());
    }
}
Then I use it:
        foreach (var c in db.ActCategories)
        {
            lst.Items.Add(c.ActType);
        }
All works fine. However, if I change access modifier (AM) for ActCategories property from public to internal, then the code doesn't work (System.NullReferenceException for db.ActCategories). As soon as I set public AM back, all works fine.
Here's strange thing I can't understand: if class is internal, then no other member's AM can be higher than class' AM. In other words, the greatest AM ActCategories can have is internal.
There's no sense in making DbSet public until class is also public. However, EF requires properties to be public - even the class is internal. This is really strange behavior and I think it should be fixed up.

Viewing all articles
Browse latest Browse all 1793

Trending Articles



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