0

LINQ で結合クエリを書き直す方法を理解しようとしています。

SELECT cs.qid,cs.qk FROM location_table pl
JOIN (SELECT qid,qk FROM q_table WHERE att5 = 'process') cs ON pl.qck = cs.qk
WHERE pl.location = 'there' 

これは私が始めたLINQですが、上記のSQLと同じ結果を返していません

from pl in location_table
from cs in q_table
where s. att5 == 'process'
&& cs.qk == pl.qck
&& pl. location == 'there'

ご協力いただきありがとうございます。

4

2 に答える 2

3

joinキーワードを使用する必要があります

from pl in location_table
join cs in q_table
    on cs.qk equals pl.qck
where cs.att5 == ‘process’ && pl. location == ‘there’
select new{cs.qid, cs.qk}

EXISTSq_table からの出力のみが必要なので、これを として書き換えたい場合:

SELECT qid,qk 
FROM q_table AS cs
WHERE EXISTS
    (
        SELECT 1 
        FROM location_table pl
        WHERE pl.qck = cs.qk AND pl.location = 'there'
    )
    AND cs.att5 == 'process'

次のようにします。

from cs in q_table
where location_table.All(pl=>pl.qck == cs.qk && pl.location == 'there')
    && cs.att5 == 'process'
select new{cs.qid, cs.qk}

それらはすべて同じ結果になるはずです。パフォーマンスチェックはあなたにお任せします:)

于 2012-04-05T16:00:48.097 に答える
0

明示的な結合を使用してみましたか?

from pl in location_table
join cs in q_table on cs.qk equals pl.qck
where s. att5 == 'process'
&& pl. location == 'there'
于 2012-04-05T16:29:45.260 に答える