Inconsistent Availability: Property Type in DbContext

I added Dbset to Context ie

public Dbset<Demo> Demo{ get; set; } 

but I get a compilation error here.

 Error 1 Inconsistent accessibility: property type 'System.Data.Entity.DbSet<MVC.Model.Demo>' is less accessible than property 'MVC.Model.Demo' D:Files/project 210 34 MVC.Data 

Here is my model: -

 class Demo { [Key] [Display(Name = "ID", ResourceType = typeof(Resources.Resource))] public long Id { get; set;} [Display(Name = "CountryID", ResourceType = typeof(Resources.Resource))] public long CountryId { get; set; } [Display(Name = "RightID", ResourceType = typeof(Resources.Resource))] public long RightId { get; set; } [Display(Name = "Amount", ResourceType = typeof(Resources.Resource))] public double Amount { get; set; } } 
+6
source share
1 answer

Demo does not have an access modifier, and the default classes are internal , so it is less accessible than the DbSet Demo , which is public . In addition, you should probably call DbSet Demos so as not to confuse them, and since it semantically contains a set of demos.

Since the kit is publicly available:

  public DbSet<Demo> Demo { get; set; } 

You also need to make the Demo class public:

 public class Demo { .... } 

As already mentioned, I also suggest changing the set:

 public DbSet<Demo> Demos { get; set; } 

so that you do not confuse the set with the class type.

+15
source

All Articles