2016-11-11 9 views
0

を使用してそれはラムダ式を使用して可能ですか?割り当て値リストで、私は次のクラスを持つラムダ式

List<ProviderQualificationDetail> providerQualificationDetail = new List<ProviderQualificationDetail>(); 

foreach (ProviderModel providers in allProviders) 
{ 
    if(!providerQualificationDetail.Any(p=>p.ProviderName.Contains(providerName))) 
    { 
     ProviderQualificationDetail ProviderQualificationDetail = new ProviderQualificationDetail(); 
     ProviderQualificationDetail.ProviderName = providerName; 
     ProviderQualificationDetail.ProviderQualificationTime = Math.Round(processingTime).ToString(); 
     ProviderQualificationDetail.TotalServiceableOffers = "Not serviceable"; 
     providerQualificationDetail.Add(ProviderQualificationDetail); 
    } 
    else 
    { 
     //Lambda expression here 
    } 
} 
+0

は、それはProviderModel.providerNameですか? – James

答えて

0

....これを試してみてください:

foreach (var item in providerQualificationDetail.Where(x => x.ProviderName== providerName)) 
{ 
item.ProviderQualificationTime = Math.Round(processingTime).ToString(); 
} 

それとも

providerQualificationDetail.Where(x => x.ProviderName == ProviderName).Select(c =>      
{ 
c.ProviderQualificationTime = "new time "; 
return providerQualificationDetail; 
}).ToList(); 

それとも

providerQualificationDetail.ForEach(x => 
{ 
if(x.ProviderName == ProviderName) 
x.ProviderQualificationTime = "new time"; 
}); 
0

他の部分では、このような

List<ProviderQualificationDetail> providerQualificationDetail = new List<ProviderQualificationDetail>(); 

foreach (ProviderModel providers in allProviders) 
{ 
    if(!providerQualificationDetail.Any(p=>p.ProviderName.Contains(providerName))) 
    { 
     ProviderQualificationDetail ProviderQualificationDetail = new ProviderQualificationDetail(); 
     ProviderQualificationDetail.ProviderName = providerName; 
     ProviderQualificationDetail.ProviderQualificationTime = Math.Round(processingTime).ToString(); 
     ProviderQualificationDetail.TotalServiceableOffers = "Not serviceable"; 
     providerQualificationDetail.Add(ProviderQualificationDetail); 
    } 
    else 
    { 
var qualificationDetail = providerQualificationDetail.SingleOrDefault(p => p.ProviderName.Equals(providerName)); 
//Assing your values here 
//example; 
qualificationDetail.ProviderName = NewProviderName.ToString(); 
providerQualificationDetail.SaveChanges(); 
    } 
} 
関連する問題