我有点卡在这上面了。基本上,我想在LINQ to SQL中执行类似以下SQL查询的操作:
SELECT f.*
FROM Foo f
WHERE f.FooId IN (
SELECT fb.FooId
FROM FooBar fb
WHERE fb.BarId = 1000
)
我们将非常感谢您的帮助。
发布于 2008-09-09 08:39:47
看看this article吧。基本上,如果您想获得IN的等价物,则需要首先构造一个内部查询,然后使用Contains()方法。以下是我的翻译尝试:
var innerQuery = from fb in FoorBar where fb.BarId = 1000 select fb.FooId;
var result = from f in Foo where innerQuery.Contains(f.FooId) select f;
发布于 2008-09-09 08:51:33
在LINQ to SQL中实现IN的一般方法
var q = from t1 in table1
let t2s = from t2 in table2
where <Conditions for table2>
select t2.KeyField
where t2s.Contains(t1.KeyField)
select t1;
在LINQ to SQL中实现EXISTS的一般方法
var q = from t1 in table1
let t2s = from t2 in table2
where <Conditions for table2>
select t2.KeyField
where t2s.Any(t1.KeyField)
select t1;
发布于 2008-09-09 07:26:53
from f in Foo
where f.FooID ==
(
FROM fb in FooBar
WHERE fb.BarID == 1000
select fb.FooID
)
select f;
https://stackoverflow.com/questions/51339
复制相似问题