0
var AddQuery = from newdist in newSpec.Distributions
where !(from oldDist in oSpec.Distributions
select oldDist.Id).Contains(newdist.Id)
select newdist;
foreach (var dist in AddQuery)
{
dist.operation="Add";
}
var updateQuery = from oldDistributionForUpdate in ospec.Distributions
where (from newDistributionForUpdate in newspec.Distributions
select newDistributionForUpdate.DistributionId).Contains(oldDistributionForUpdate.DistributionId)
&&
(from newDistributionForUpdate in newpaymentSpecification.Distributions
select newDistributionForUpdate.Amount).Equals(oldDistributionForUpdate.Amount)
select oldDistributionForUpdate;
foreach (var dist in updateDistQuery)
{
dist.operation = "Update";
}
我打算有對象的集合來自查詢結果&對它們進行處理,有沒有更簡單的方式來實現我在做什麼遍歷對象的最佳方式?什麼是使用LINQ
我覺得你迭代集合的方式是最簡單的方法。你可以做'AddQuery.ToList()。ForEach(i => i.operation =「Add」)' –