如何使用lambda将linq写入sql用于此sql查询

时间:2013-08-19 07:04:32

标签: linq lambda

朋友们,请帮助我摆脱这个对linq的新人

select cn from color,related
where cid in (select ciid from related where iid=2)

2 个答案:

答案 0 :(得分:0)

在不知道如何建立关系的情况下,我能做的最好的事情就是自由发挥,像是;

(from c in db.color
 from r in db.related
 where c.cid == r.ciid && r.iid == 2
 select c).Distinct();

from c in db.color
where (from r in db.related where r.iid==2 select r.ciid).Contains(c.cid)
select c;

答案 1 :(得分:0)

尝试下面的表达

(from i in dbcontext.color
where (from j in  dbcontext.color where j.iid==2 select j.ciid).contains(i.cid)
select i)