Here is my current relationship
DataRelation relation = new DataRelation("EventCategoryRelation", eventsTable.Columns["event_id"], eventCategoriesTable.Columns["event_id"]);
ds.Tables.Add(eventsTable);
ds.Tables.Add(eventCategoriesTable);
ds.Relations.Add(relation);
Here is a quick look through the tables
EventsTable
event_id | event_description
1 || "First Event"
EventCategoriesTable
event_category_id || event_id || category_id
1 || 1 || 1
2 || 1 || 2
Relationship is many-to-many (one event is to many categories)
Here is how I populate my DTO's using a foreach loop
foreach (DataRow row in eventsTable.Rows)
{
Event events = new Events();
events.Description = row["event_description"].ToString();
DataRow[] aDr = row.GetChildRows("EventCategoryRelation");
foreach (DataRow dr in aDr)
{
Categories category = new Categories();
category.CategoryID = Int64.Parse(dr["category_id"].ToString());
events.CategoryList.Add(category);
}
}
I have more fields on my actual code. I want to replace the foreach loop with a LINQ query. Is that possible?