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

上一篇:thinkphp开发技巧经验分享


下一篇:疯狂的表单-html5新增表单元素和属性