ef 三表关联查询
/// 会议名称
public class HY
{
public int HYID { get; set; }
public virtual List<HYDD> HYDD { get; set; }
}
/// 会议地点
public class HYDD
{
public int HYDDID { get; set; }
public int HYID { get; set; }
public int ZYID { get; set; }
public ZY ZY { get; set; }
}
///会议室资源
public class ZY
{
public int ZYID { get; set; }
public string Name { get; set; }
}
int ZYID=2;
List<int> ZYIDs = {2,5,8};
显示会议列表
var tab = from s in db.HYs.Include(h => h.HYDD.Select(c => c.ZY))
select s;
查一个ZYID时可以这样写:
tab = tab.Where(s => s.HYDD.Select(d => d.ZY.ZYID ).Contains(ZYID));
查ZYIDs时该怎么写?
tab = tab.Where(s =>ZYIDs.Contains(s.HYDD.Select(d => d.ZY.ZYID)))报错呀
------解决方案-------------------- tab = tab.Where(s => s.HYDD.Select(d => d.ZY.ZYID).Any(x=>ZYIDs.Contains(x.ZYID)));