2014-03-06 58 views
6
属性类型

我已经在上下文中添加Dbset即可访问性不一致:在的DbContext

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

,但我在这里得到编译错误,即

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 

这里是我的模型: -

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; } 
    } 

回答

15

Demo默认情况下没有访问修饰符,类别为internal,所以它不是比DbSetDemo这是public可访问。此外,您应该拨打DbSetDemos以免混淆两者,并且从语义上讲,它包含一组演示。

由于集众:

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

你需要做Demo类公众以及:

public class Demo 
{ 
    .... 
} 

如前所述,我也建议你更改设置为:

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

这样您就不会将该集合与类类型混淆。

+0

如果我从上面的代码中删除“公共”,那么它会成功编译,但是然后我无法从控制器页面访问分配模型。那么该怎么做? – user3206357

+0

@ user3206357 - 您需要公开分配。 – acarlon

+0

@ user3206357 - 查看更新。 – acarlon