Lambda Expression에서 기본적인 Join은 다음과 같은 구분을 따릅니다. Key에 해당하는 정보가 양쪽 Table에 존재하는 경우에만 조회됩니다.
var result = sourceTable .Join <SourceTableType, JoinedTableType, MappingKeyType, ResultType> (joinedTables, sourceTableParameter => sourceTableParameter.mappingKeyColumn, joinedTableParameter => joinedTableParameter.mappingKeyColumn, (sourceTableParameter, joinedTableParameter) => new ResultType { .... });
예제
IEnummerable<StudentsInUniversity> result = universities.Join <University, Student, long, StudentsInUniversity> (students, u => u.UniversityId, s => s.UniversityId, (u, s) => new StudentsInUniversity { StudentName = s.Name, UniversityName = u.Name });
Left Outer Join은 다음과 같은 다른 구문을 가집니다.
var result = sourceTable .GroupJoin(joinedTable, sourceTableParameter => sourceTableParameter.mappingKeyColumn, joinedTableParameter => joinedTableParameter.mappingKeyColumn, (sourceTableParameter, joinedTableParameter) => new { sourceTable = sourceTableParameter, joinedTable = joinedTableParameter}) .SelectMany( t => t.joinedTable.DefaultIfEmpty(), (groupedList, joinedTalbe) => new { .... });
IEnummerable<StudentsInUniversity> result = universities .GroupJoin(students, u => u.UniversityId, s => s.UniversityId, (u, s) => new { universities = u, students = s }) .SelectMany( t => t.students.DefaultIfEmpty(), (grouped, s) => new StudentsInUniversity { UniversityName = grouped.unversities.Name, StudentName = s.Name, });