I'm wondering if filling a list of objects in an object can be done quicker than what i see when i run it. I fill the CABCodes- & CABDetails-lists with a simple query using Dapper with .ToList();
So both the lists are in memory, yet the foreach-operation takes around 20 seconds.
CABCodes: ~10,000 objects
CABDetails: ~60,000 objects
List<CABCode> CABCodes = new List<CABCode>();
List<CABDetail> CABDetails = new List<CABDetail>();
public class CABCode {
public int Sequence { get; set; }
public string Code { get; set; }
public int Group { get; set; }
public List<CABDetail> Details { get; set; }
}
public class CABDetail {
public int CABSequence { get; set; }
public int Proptype { get; set; }
public string Propvalue { get; set; }
}
foreach (var c in this.CABCodes) {
c.Details = this.CABDetails.Where(x => x.CABSequence == c.Sequence).ToList();
}
Is there a far more efficient method of accomplishing this?