我在上下文中添加了Dbset,即
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; } }
解决方法
Demo没有访问修饰符,默认情况下类是内部的,因此它比公共的DbSet Demo更难访问.此外,您可能应该调用DbSet演示,以免混淆两者,从语义上来说它拥有一组演示.
由于该集是公开的:
public DbSet<Demo> Demo { get; set; }
您还需要公开Demo类:
public class Demo { .... }
如上所述,我还建议您将设置更改为:
public DbSet<Demo> Demos { get; set; }
这样你就不会将集合与类类型混淆.