可访问性不一致错误

时间:2015-02-01 13:19:11

标签: c# asp.net-mvc visual-studio

我的错误:

  

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; }
}

2 个答案:

答案 0 :(得分:3)

两个错误都意味着相同的事情:通用类型ListDbSet的类型参数,即OrderDetailMvcMusicStore.Models.Artist未在代码中标记为公开,他们在您的包装内部的可视性。这意味着这些类型不能用于public属性。

有两种解决方法:

  • 您可以输入public
  • 类型
  • 您可以制作属性internal

选择哪种行动方案取决于项目中OrderDetailsArtists的可访问性要求。

答案 1 :(得分:1)

为了更简洁,您的错误会精确定位OrderDetails以及您应该纠正的位置。 请检查您的课程 OrderDetail ,其开头为: 类OrderDetail 预先附加公众,使其显示为: 公共类OrderDetail