0

我有这个 sql 查询。我可以将大部分查询转换为 linq,但我不明白如何在这个特定查询中实现“不在”部分。这是我的查询:

SELECT d.processid,d.name,t.test_name
FROM dc_tp_tprocess d
left outer join dc_tp_tprocedured pd on pd.processid=d.processid
left outer join dc_tp_test t on t.procedureid=pd.procedureid
where d.active='Y' and t.testid=1 
                   and d.processid not in (1,2,6,8,9,10)
order by t.testid,d.processid
4

1 回答 1

1

像这样:

int[] tmp=new int[]{1,2,6,8,9,10};

var query=from d in dc_tp_tprocess
          join pd in dc_tp_tprocedured on d.processid equals pd.processid into leftGroup1
          from pd in leftGroup1.DefaultIfEmpty() 
          join t in dc_tp_test on pd.procedureid equals t.procedureid into leftGroup2
          from t in leftGroup2.DefaultIfEmpty()
          orderby t.testid,d.processid
          where d.active=="Y" && t.testid==1 && !tmp.Contains(d.processid)
          select new {d.processid,d.name,test_name=t==null?"":t.test_name};
于 2013-06-27T07:19:59.623 回答