2017-08-24 4 views
0

に参加:私はLINQのにこれを変換したいLINQ

SELECT  {fields} 
FROM  tableA AS A 
LEFT JOIN tableB AS B 
ON    B.Field1 = MyVariable 
AND   ( A.Key = B.Key 
       OR A.Key = B.AlternateKey) 

それはそのOR私をトリップされるAND句と連動しています。

EDIT:拡張機能として解決策を用意してください。

答えて

1
from a in tableA 
    from b in tableB.Where(b => b.Field1 == MyVariable && (a.Key == b.Key || a.Key == b.AlternateKey)).DefaultIfEmpty() 
    select new { a, b }; 

tableA.SelectMany(
    a => tableB.Where(b => b.Field1 == MyVariable && (a.Key == b.Key || a.Key == b.AlternateKey)).DefaultIfEmpty() 
    .Select(b => new { a, b }) 
); 
+0

ありがとう、私は拡張メソッドとして持っていますか? – Jack

+0

@Jack updated – Sergey

+0

恐ろしい、ありがとう。 – Jack

関連する問題