Entity Framework 多对多查询的写法

同学们,看下面的代码段就明白了:

一对多:

public ICollection<ReportLookup> GetReportLookup(IEnumerable<Guid> specialityID)
{
var list = _Repo.All(p => specialityID.Contains(p.Speciality.Id)).ToList();
return list;
}

多对一:

public ICollection<ReportLookup> GetReportLookup(Guid specialityID)
{
var list = _Repo.All(p => p.Specialitys.Contains(specialityID)).ToList();
return list;
}

多对多:

public ICollection<ReportLookup> GetReportLookup(IEnumerable<Guid> specialityID)
{
var list = _Repo.All(p =>  p.Specialitys.Any(x => specialityID.Contains(x.Id))).ToList();
return list;
}

posted @ 2013-07-15 17:16  wxing67  阅读(353)  评论(1编辑  收藏  举报