2011-08-08 13 views
0
select * 
    from Table1 
where TC in (select TC 
       from Table2 
       where Application in ('AAA'))` 

上記のクエリをLINQに変換するのに役立ちます。このようサブクエリSQLとLINQの相関

+0

マッピングクラスにコードを貼り付けてください。 –

答えて

1

詳細を取得SQLに相当します。

from t1 in db.Table1s 
where db.Table2s.Select(t2 => t2.TC).Contains(t1.TC) 
from t1 in db.Table1s 
(私がいかに間違っている!)

UPDATE

List<string> myCollection = new List<string> { "AAA" }; 
from t1 in db.Table1s 
where db.Table2s.Where(t2 => myCollection.Contains(t2.Application)).Select(t2 => t2.TC).Contains(t1.TC) 
from t1 in db.Table1s 

は、インコードのコレクションで動作するはずです。

+0

ありがとうございます。 –

0

てみてくださいにはLINQのサブクエリ「は、」(今のところ)ありません。

「Any」演算子を使用して同じことを達成します。例えば

従業員

from c in db.Customers 
    where db.Employees.Any(e => e.City == c.City) 
    select c; 

又は

と同じ都市に位置しているすべての顧客.ANY()演算子の左辺でありますサブクエリ。

query.Any(x => predicate) 

が、これは非常に簡単に見えます

EXISTS(
    SELECT * 
    FROM query 
    WHERE predicate 
    ) 

where Application in ('AAA')一部がなければ、ここで

http://social.msdn.microsoft.com/Forums/en-AU/linqprojectgeneral/thread/360166df-4e50-44d8-812a-04b5bc4fedd1

+0

このURLもご確認ください。http://msdn.microsoft.com/en-us/vcsharp/aa336746 –

関連する問題