I have created simple context class:
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.
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.