2016-10-18 9 views
1

私はLinqで新しく、このSQLクエリをLinq形式に変換したいと思います。複数の操作方法Linqでの選択場所

これは、SQL形式

select * 
from investorwallets iw 
where transactionid in 
(select investordepositid from investordeposits) 
or transactionid in 
(select withdrawalid from investorwithdrawals) 
or transactionid in 
(select paymentdistributionid from paymentdistributions) 

である私もこのSO質問に見てきたが、私のために

EDIT運

は、これは私が試したものではありません。私はそれをテストするためにLinqpadを使用する

from iw in Investorwallets 
where (
      from id in Investordeposits // I got error from here 
      select id.investordepositid 
     ) 

誰でも手伝ってくれますか?

はあなたに

+1

はIW( '.Containsを追加します。トランザクションid) '。そして、 '||'で他のcriteriasと同様のことをしてください。 –

答えて

1

ありがとう最も直接的である:

from iw in investorwallets 
where investordeposits.Any(iten => item.investordepositid == iw.transactionid) || 
     investorwithdrawals.Any(iten => item.withdrawalid == iw.transactionid) || 
     paymentdistributions.Any(item => item.paymentdistributionid == iw.transactionid) 
select iw; 

しかしあなたはまた、その後、労働組合の結果と.Containsを行うことができます。

var ids = investorwithdrawals.Select(item => item.investordepositid) 
          .Union(investorwithdrawals.Select(item => item.withdrawalid)) 
          .Union(paymentdistributions.Select(item => item.paymentdistributionid)); 

var result = investorwallets.Where(item => ids.Contains(item.transactionid)); 
+1

こんにちは、それを試し、あなたにすぐに更新されます、ありがとう – Webster

+1

それはおいしいです。受け入れられた答えとしてマークされています。ありがとう:) – Webster

+1

@Webster - あなたは歓迎です:) –

1
 List<investorwallet> investorwallets = GetInvestorwallets(); 
     List<investordeposit> investordeposits = GetInvestordeposits(); 
     List<investorwithdrawal> investorwithdrawals = GetInvestorwithdrawals(); 
     List<paymentdistribution> paymentdistributions = GetPaymentdistribution(); 

     List<investorwallet> newList = investorwallets.Where(x => investordeposits.Any(y=>y.investordepositid == x.transactionid) 
             || investorwithdrawals.Any(y => y.withdrawalid == x.transactionid) 
             || paymentdistributions.Any(y => y.paymentdistributionid == x.transactionid)).ToList(); 
+0

助けてくれてありがとう、私はgiladの答えをマークする必要があります、彼は最初です。 :) – Webster

関連する問題