我有点困惑于此.基本上我想在LINQ to SQL中执行类似以下SQL查询的操作:
SELECT f.* FROM Foo f WHERE f.FooId IN ( SELECT fb.FooId FROM FooBar fb WHERE fb.BarId = 1000 )
我们将非常感激地提供任何帮助.
谢谢.
var q = from t1 in table1 let t2s = from t2 in table2 where在LINQ to SQL中实现EXISTS的一般方法select t2.KeyField where t2s.Contains(t1.KeyField) select t1;
var q = from t1 in table1 let t2s = from t2 in table2 whereselect t2.KeyField where t2s.Any(t1.KeyField) select t1;
看看这篇文章.基本上,如果要获得等效的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;