我有下面列出的linq语句,我想根据另一个表中的值限制一个表中的记录。这是我的代码:
using (context = new DocEntityConnection())
{
var Docs = context.tbDocsDetails.Where(md => md.IsCurrentDetails && md.tbDoc.StatusID == 9).ToList();
this.approves = context.tbDocApproves.ToList().Where(a => Docs.Select(x => x.DocID).ToList().Contains(a.DocID)).ToList();
return Docs.Select(md => GetDataItem(md)).ToList();
}
另一个名为tbDocStatus
的表格也有DocId
字段
我只想从tbDocDetails
tbDocdetails.DocId = tbDocStatus.DocId
和tbDocStatus.StatusId = 4
返回记录。
我如何将其添加到上面显示的代码中?
答案 0 :(得分:0)
您需要的是join
var Docs = from docDetail in context.tbDocsDetails
join docStatus in context.tbDocStatus
on docDetail.DocId = docStatus.DocId
where docStatus.StatusId == 4
select docDetail;
答案 1 :(得分:0)
using (context = new DocEntityConnection())
{
var Docs = context.tbDocsDetails.Where(md => md.IsCurrentDetails && md.tbDoc.StatusID == 9).ToList();
var DocsFiltered = from d in Docs
join docStatus in context.tbDocStatus
on d.DocId equals docStatus.DocId
where docStatus.StatusId = 4
select d
this.approves = context.tbDocApproves.ToList().Where(a => Docs.Select(x => x.DocID).ToList().Contains(a.DocID)).ToList();
return DocsFiltered.Select(md => GetDataItem(md)).ToList();
}