0
試圖讓我的周圍LINQ和繼承映射我得到DBContext.cs異常頭:的LINQ to SQL繼承InvalidOperationException異常
Could not retrieve Table for inheritance subtype 'Movie, try Table of 'Media' instead
DBContext.cs
Media.cs
[Table(Name="media")]
[InheritanceMapping(Code = 1, Type = typeof(Movie), IsDefault=true)]
[InheritanceMapping(Code = 2, Type = typeof(Game))]
[InheritanceMapping(Code = 3, Type = typeof(Album))]
[InheritanceMapping(Code = 4, Type = typeof(Track))]
public class Media
{
[Column(IsPrimaryKey=true)]
public string itemId;
[Column]
public string title { get; set; }
[Column]
public string price { get; set; }
[Column(IsDiscriminator=true)]
public int itemType { get; set; }
}
Movie.cs
public class Movie : Media
{
[Column]
public int year { get; set; }
}
而這裏的代碼中調用了一切:
public static void GetAll()
{
using (DBContext db = new DBContext())
{
IEnumerable<Media> media = from m in db.media select m;
}
}
}
我有一種感覺,我錯過了一些討厭的映射屬性。