Scenario:
I have a generic list of Audits and a generic list of AuditImages. These two lists have been compiled from database tables. As a result of this, ONE AuditImage can have MANY Audits. As you will see below, the classes that the tables map to are joined by a foreign key relationship "ImageID" when they are in the database, however once the data is extracted to lists in code, there is no "PHYSICAL JOIN".
Classes That DB Tables Map To:
public class AuditImage
{
public Guid ImageID { get; set; }
public string LowResUrl { get; set; }
}
public class Audit
{
public Guid AuditID { get; set; }
public Guid ImageID { get; set; }
public DateTime CreatedDate { get; set; }
public string CreatedBy { get; set; }
public string Comment { get; set; }
}
The Problem:
I now want to compile a list of "Trail" objects by extracting the data from each list and combining it on "Audit.ImageID == AuditImage.ImageID", into a new list.
public class Trail
{
public Guid ImageID { get; set; }
public DateTime CreatedDate { get; set; }
public string CreatedBy { get; set; }
public string Comment { get; set; }
public string LowResUrl { get; set; }
}
(The above essentially combines the "LowResUrl" field with each Audit based on the ImageID being the same.)
The Question:
How should I go about doing this!? I had thought about using foreach loops and linq to create a new list of trail objects but I can't quite think of exactly how I would go about doing this?!
Help would be greatly appreciated.