考虑这两个表:
ClassID Name
1 C1
2 C2
ClassID List<CourseSession>
1 [Object that has value "A"], [Object that has value "B"]
2 [Object that has value "B"], [Object that has value "C"]
当我在 Linq 中加入这两个表时,我得到:
ID Name List
1 C1 [A, B]
2 C2 [A, B]
我需要扩展它们:
ID Name List
1 C1 A
1 C1 B
2 C2 A
2 C2 B
林克代码:
var classes = from row in t.AsEnumerable()
select new
{
ClassID = row.Field<Guid>("ClassID"),
ClassName = row.Field<string>("Name"),
};
var classCourses = from row in classes.AsEnumerable()
select new
{
ID = row.ID,
CourseSessionList = GetAllCoursesByID(row.ID).AsEnumerable()
};
//Attempt to join
var expandedClassCourse = from classRow in classes
join ccRow in classCourses
on classRow.ID equals ccRow.ID
into filteredExpandedClasses
select filteredExpandedClasses;
我不确定如何实现这一目标。有任何想法吗?