c# DbSet - Internal object cannot be got

后端 未结 2 1604
野性不改
野性不改 2021-01-04 15:03

I need to switch an entity to internal. So I create it. No build/runtime error. But when I want to use the DbSet object I can\'t because the object seems not initialized !

相关标签:
2条回答
  • 2021-01-04 15:31

    I just had the same problem and was able to fix it by only setting the getter as internal.

    public partial class Entities
    {
       public DbSet<Employee> EmployeeSet { internal get; set; }
    }
    
    0 讨论(0)
  • 2021-01-04 15:42

    It will not be automatically instantiated if it is not set to public. You can manually instantiate it using Set<TEntity>() method.

    public partial class Entities
    {
       internal DbSet<Employee> EmployeeSet { get; set; }
    
       public Entities()
       {
           EmployeeSet = Set<Employee>();
       }
    }
    
    0 讨论(0)
提交回复
热议问题