태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.
   情  
Front Page
Tag | Location | Media | Guestbook | Admin   
 
Lambda Expression으로 Join사용하기

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,
        });

name    password    homepage
 hidden


 Category
분류 전체보기 (95)
Netwrok & Security (6)
Web Development (61)
Database (5)
Framework (6)
Others (17)
About (0)
 TAGS
: ajax Android APM application error #401 ASP ASP.NET asp.net ajax ASP.NET Machine at ATRIX ATX ATX와BTX의차이 Auto-Negotiation back-end bash shell Bit ending Blog API BTX c#.net CentOS class id 차이 CSMACD data tier Database DB DB동작원리 DB처리과정 DTD ebnf ethereal ethernet exception firefox2 설치 font-family Framework과 자동로그인 front-end FTP get post 우선순위 hotmail
 Calendar
«   2018/08   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
 Visitor Statistics
Total : 264,790
Today : 22
Yesterday : 58
rss
 

티스토리 툴바