どのようにすることができますを取り扱INサブクエリの商品?
-
09-06-2019 - |
質問
いてはちょっとしたこだわった。基本的にはもう少し前向きなことをやりたい、以下のようなSQLクエリー中の商品:
SELECT f.*
FROM Foo f
WHERE f.FooId IN (
SELECT fb.FooId
FROM FooBar fb
WHERE fb.BarId = 1000
)
他の助けがなどの言語を受信します。
感謝。
解決
してい この記事.基本的には、取得したい場合は、相当の、を構築することも必要である内部クエリを最初に含む()メソッドがあります。ここでの私の試みで翻訳:
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;
他のヒント
一般道で実施する商品
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
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;
from f in Foo
where f.FooID ==
(
FROM fb in FooBar
WHERE fb.BarID == 1000
select fb.FooID
)
select f;
使ってみ二つの別々のステップ
// create a Dictionary / Set / Collection fids first
var fids = (from fb in FooBar
where fb.BarID = 1000
select new { fooID = fb.FooID, barID = fb.BarID })
.ToDictionary(x => x.fooID, x => x.barID);
from f in Foo
where fids.HasKey(f.FooId)
select f
作辞書/Set/コレクションのfids初
var fids = (from fb in FooBar
where fb.BarID = 1000
select new { fooID = fb.FooID, barID = fb.BarID })
.ToDictionary(x => x.fooID, x => x.barID);
from f in Foo
where fids.HasKey(f.FooId)
select f
してみてください
var fooids = from fb in foobar where fb.BarId=1000 select fb.fooID
var ff = from f in foo where f.FooID = fooids select f
var foos = Foo.Where<br>
( f => FooBar.Where(fb.BarId == 1000).Select(fb => fb.FooId).Contains(f.FooId));
from f in foo
where f.FooID equals model.FooBar.SingleOrDefault(fBar => fBar.barID = 1000).FooID
select new
{
f.Columns
};
作辞書/Set/コレクションのfids初
var fids = (from fb in FooBar where fb.BarID = 1000 select new { fooID = fb.FooID, barID = fb.BarID }) .ToDictionary(x => x.fooID, x => x.barID);
from f in Foo where fids.HasKey(f.FooId) select f
所属していません StackOverflow