【发布时间】:2011-09-30 20:25:27
【问题描述】:
我已经上了我的 DB 3 表
movies、workers、workermovies(这是关系表)
public class Movie
{
public Movie()
{
Genres = new List<Genre>();
Formats = new List<Format>();
ProductionCompanies = new List<ProductionCompany>();
Workers = new List<Worker>();
}
public int Id { get; set; }
public string Title { get; set; }
public DateTime ReleaseDate { get; set; }
public string StoryLine { get; set; }
public int RunTime { get; set; }
[ForeignKey("MPAARateId")]
public MPAARate MPAARate { get; set; }
public int MPAARateId { get; set; }
public byte[] ImageData { get; set; }
public string ImageMimeType { get; set; }
public DateTime CreatedDate { get; set; }
public string OfficialSite { get; set; }
public int Budget { get; set; }
public int StatusId { get; set; }
public virtual ICollection<Genre> Genres { get; set; }
public virtual ICollection<Format> Formats { get; set; }
public virtual ICollection<ProductionCompany> ProductionCompanies { get; set; }
public virtual ICollection<Worker> Workers { get; set; }
}
public class Worker
{
public int Id { get; set; }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public DateTime Birthday { get; set; }
public string Biography { get; set; }
public string BornName { get; set; }
public double Height { get; set; }
public DateTime? Died { get; set; }
public byte[] ImageData { get; set; }
public string ImageMimeType { get; set; }
public bool IsActor { get; set; }
public bool IsDirector { get; set; }
public bool IsWriter { get; set; }
public bool IsProducer { get; set; }
public bool IsStar { get; set; }
public virtual ICollection<Movie> Movies { get; set; }
}
在这个关系中,我得到了 movieId 和 workerId
但如果这个人演戏、写作或制片人等,我也会得到更多的领域。
如果需要,我如何定义 relation entity 类
当我只想得到在电影中表演的人时,我怎么写这样一个 linq
查询
【问题讨论】:
-
附带提示:如果您不想只获得电影中的角色,则需要更改架构。因为不是每个演员都出演过他们合作过的所有电影。 (就像梅尔吉布森没有出演《启示录》,但他导演了它......)
标签: linq entity-framework-4.1 ef-code-first