2016-10-11 9 views
-2

私はラムダに変換しようとしていますが、成功できませんでした。 linqまたはlambdaに変換する方法はありますか?ラムダまたはlinqへのネストされたforeachループの変換

foreach (var tempitem in mbsRateTempList) 
{ 
    foreach (var Saveditem in mbsSavedRecordList) 
    { 
     if (tempitem.MbsSecurityId == Saveditem.MbsSecurityId && tempitem.CouponRate == Saveditem.CouponRate 
       && tempitem.SettlementMonth.Month == Saveditem.SettlementMonth.Month && tempitem.Price == Saveditem.Price) 
     { 
      TobeDeletedIds.Add(Saveditem.Id); 
      MatchedIdsInTempList.Add(tempitem.TempId); 
      //mbsSavedRecordList[0].ObjectState=Repository.Pattern.Base.Infrastructure.ObjectState. 
     } 
     //else 
     //{ 

     //} 
    } 
} 
+0

ようこそ。使用しているデータの例、所有しているコードエンティティ、エラーがあります。あなたの質問を編集しても問題ありません。 –

答えて

0

することはでき、関連するすべてのプロパティを含む匿名型のJoin:スタックオーバーフローへ

var objectsToAdd = from tempitem in mbsRateTempList 
        join saveditem mbsSavedRecordList 
        on new { tempitem.MbsSecurityId, tempitem.CouponRate, tempitem.SettlementMonth.Month, tempitem.Price } 
        equals new { saveditem.MbsSecurityId, saveditem.CouponRate, saveditem.SettlementMonth.Month, saveditem.Price } 
        select new { tempitem, saveditem }; 

foreach(var x in objectsToAdd) 
{ 
    TobeDeletedIds.Add(x.saveditem.Id); 
    MatchedIdsInTempList.Add(x.tempitem.TempId); 
} 
関連する問題