Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inconsistent accessibility: property type in DbContext

I have added Dbset in Context i.e.

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

but I am getting compilation error here i.e.

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; }
    }
like image 659
user3206357 Avatar asked Mar 06 '14 10:03

user3206357


2 Answers

Demo has no access modifier and classes are internal by default, so it is less accessible than the DbSet Demo which is public. Also, you should probably call the DbSet Demos so as not to confuse the two and since semantically it holds a set of Demos.

Since the set is public:

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

You need to make the Demo class public as well:

public class Demo
{
     ....
}

As mentioned, I also suggest you change the set to:

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

so that you don't confuse the set with the class type.

like image 128
acarlon Avatar answered Nov 15 '22 22:11

acarlon


you should make your model public, so just change it to

public class Demo{}
like image 33
hossein andarkhora Avatar answered Nov 16 '22 00:11

hossein andarkhora