asp.net-mvc – 不一致的可访问性:DbContext中的属性类型
发布时间:2020-05-24 13:05:01 所属栏目: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 M
|
我在上下文中添加了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; }
这样你就不会将集合与类类型混淆. (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – ASP.NET Core MVC:设置身份cookie的到期
- 什么是asp.net会话超时的单位?
- asp.net – 程序或函数期望未提供的参数
- asp.net-mvc – 在ASP.Net MVC中,如何创建将javascript和cs
- asp.net – FederatedAuthentication.WSFederationAuthenti
- asp.net-mvc – 在请求之间保持/缓存数据 – 常用方法
- asp.net-mvc – 带有lambda表达式的ASP.net MVC Action URL
- asp.net – OutOfMemoryException当发送大文件500MB使用Fil
- asp.net-mvc – 如何实现在jqgrid搜索?
- asp.net-web-api – 默认请求标头不接受任何值,它始终为nul
推荐文章
站长推荐
热点阅读
