我正在尝试根据其子集合的子集合中的值订购“父”项目列表。以下是具体...
我有一个 Film 实体(映射到 Films 表),它具有一对多的 Release 实体集合(映射到 Releases 表)。每个 Release 都有一个或多个 ReleaseDate 实体(映射到 ReleaseDates 表)。
public class Film {
public int Id {get;set;}
public string Title {get;set;}
/* ... more properties here ...*/
}
public class Release {
public int Id {get;set;}
public int FilmId {get;set;}
public virtual Film Film {get;set;}
public virtual ICollection<ReleaseDate> ReleaseDates { get; set; }
/* ... more properties here ...*/
}
public class ReleaseDate {
public int Id {get;set;}
public DateTime Date {get;set;}
public int ReleaseId {get;set;}
public virtual Release Release {get;set;}
/* ... more properties here ...*/
}
现在,我想按最早的发行日期订购电影,但显然一部电影可能没有发行,发行也可能没有发行日期(同样,1-* 关系)。SQL 等价物将是...
SELECT * /* or whatever columns...*/
FROM dbo.Films F
LEFT OUTER JOIN dbo.Releases R ON R.FilmId = F.Id
LEFT OUTER JOIN dbo.ReleaseDates RD ON RD.ReleaseId = R.Id
ORDER BY RD.[Date] ASC /* or DESC */
我该怎么做呢?