There are 2 classes :
public class RiseData{
public int AccountId{get;set;}
public List<CashData> CashList{get;set;} //and other params
}
public class CashData{
public int AccountId{get;set;} //and other params
}
I am getting some data in form as below:
List<RiseData> distinctRiseData = riseDataList.FindAll(x => x.RecordType == "P").ToList();
List<Cash> cashListDirty = cashList.FindAll(x => x.RecordType == "C").ToList();
I am trying to fill the cashListDirty to distinctRiseData on the basis of where distinctRiseData.Record.AccountId=cashListDirty.Record.AccountId
Lets say there are 10 records in cashListDirty where 2 records have same AccountId as 1 record in distinctRiseData . I should add those 2 records in distinctRiseData record with the same AccountId.
Tried this but doesn't works:
foreach(var i in distinctRiseData )
{
var data = cashListDirty .FindAll(x => x.AccountId == i.AccountId).ToList();
i.CashList.Add(data);
}
Thanks.
question from:
https://stackoverflow.com/questions/65942930/add-a-list-in-parent-list-on-basis-of-parameter 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…