我在上下文中添加了 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
没有访问修饰符,类是 internal
默认情况下,它比 DbSet
更难访问Demo
这是public
.另外,您应该调用DbSet
Demos
以免混淆这两者,因为它在语义上包含一组演示。
由于该集合是公开的:
public DbSet<Demo> Demo { get; set; }
您还需要公开 Demo 类:
public class Demo
{
....
}
如前所述,我还建议您将设置更改为:
public DbSet<Demo> Demos { get; set; }
这样您就不会将集合与类类型混淆。
关于asp.net-mvc - 可访问性不一致 : property type in DbContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22221393/