我的错误:
Error 1 Inconsistent accessibility: property type 'System.Data.Entity.DbSet<MvcMusicStore.Models.OrderDetail>' is less accessible than property 'MvcMusicStore.Models.MusicStoreEntities.OrderDetails' C:\Users\Jose\documents\visual studio 2013\Projects\MvcMusicStore\Models\MusicStoreEntities.cs 19 35 MvcMusicStore
Error 2 Inconsistent accessibility: property type 'System.Collections.Generic.List<MvcMusicStore.Models.OrderDetail>' is less accessible than property 'MvcMusicStore.Models.Order.OrderDetails' C:\Users\Jose\documents\visual studio 2013\Projects\MvcMusicStore\Models\Order.cs 25 32 MvcMusicStore
我的代码导致这些错误:
public class Order
{
public int OrderId { get; set; }
public string Username { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string State { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public decimal Total { get; set; }
public System.DateTime OrderDate { get; set; }
public List<OrderDetail> OrderDetails { get; set; }<<<<<ERROR
另一个错误是在
public class MusicStoreEntities:DbContext
{
public DbSet<Album> Albums { get; set; }
public DbSet<Genre> Genres { get; set; }
public DbSet<Artist> Artist { get; set; }
public DbSet<Cart> Carts { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<OrderDetail> OrderDetails { get; set; }<<<<<<ERROR
public System.Data.Entity.DbSet<MvcMusicStore.Models.Artist> Artists { get; set; }
}
最佳答案
两种错误的含义都相同:通用类型List
和DbSet
的类型参数(即OrderDetail
和MvcMusicStore.Models.Artist
)在代码中未标记为公共,从而使其可见性在程序包内部。这意味着这些类型不能在public
属性中使用。
有两种解决方法:
您可以将类型设置为public
,或者
您可以将属性设置为internal
。
选择哪种操作方式取决于项目中OrderDetails
和Artists
的可访问性要求。
关于c# - 可访问性不一致错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28263121/