asp.net-mvc - 可访问性不一致 : property type in DbContext

标签 asp.net-mvc entity-framework

我在上下文中添加了 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/

相关文章:

entity-framework - Entity Framework 验证和使用

c# - 如何使用 UnitOfWork 模式从 Add 获取 id?

c# - ASP.Net MVC 5 子目录捆绑问题

asp.net - 将 ASP.Net 身份验证与 ASP.Net MVC 结合使用有什么真正的好处吗?

javascript - 在部分 View 上加载脚本文件导致错误

asp.net-mvc - 实体类型 ApplicationUser 不是当前上下文(Azure 数据库)模型的一部分

.net - 在 n 层应用程序中将连接字符串放在哪里?

c# - Url.Action 在布局页面上不起作用

entity-framework - 自定义列的 ExecuteStoreQuery

c# - Entity Framework 与 SQLite 错误 : An error occurred while reading from the store provider's data reader