加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 不一致的可访问性:DbContext中的属性类型

发布时间:2020-12-16 04:18:42 所属栏目:asp.Net 来源:网络整理
导读:我在上下文中添加了Dbset,即 public DbsetDemo Demo{ get; set; } 但我在这里得到编译错误,即 Error 1 Inconsistent accessibility: property type 'System.Data.Entity.DbSetMVC.Model.Demo' is less accessible than property 'MVC.Model.Demo' D:Files/pr
我在上下文中添加了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; }

这样你就不会将集合与类类型混淆.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读