2010-02-21 4 views
1

다음 C# 코드가 있습니다.조인 확장 메서드 구문

IQueryable<Invoice> query = service.GetInvoices(); 

    query = query.Where(inv => inv.ProjectID == projectid); 
    query = query.Skip(pageIndex * pageSize).Take(pageSize); 

가입 확장 방법을 사용하여 "상태"테이블에 가입을 추가하고 싶습니다.

많은 구문 예제를 찾을 수 없습니다.

도와 줄 수 있습니까?

코드 작성에 도움이 될 세부 사항에 참여하십시오. 나는 당신의 DB 구조를 이해하면 정확하게 내가 갈 것

var query = 
    (
    from i in service.GetInvoices() 
    join s in service.GetStatuses() on s.ID equals i.invStatus 
    where i.ProjectID == projectid 
      //add here any more where clausole you need 
    select i //you still need invoices returned? 
).Skip(pageIndex * pageSize).Take(pageSize); 

:

는 필드에 가입하여 Invoice.invStatus에

말콤

답변

2
var query = 
    (
    from i in service.GetInvoices() 
    from s in service.GetStatuses() 
    where i.ProjectID == projectid && 
      s.ID == i.invStatus //"join" condition here 
      //add here any more where clausole you need 
    select i //you still need invoices returned? 
).Skip(pageIndex * pageSize).Take(pageSize); 

을 Status.ID 조인

var query = 
    (
    from i in service.GetInvoices() 
    from s in i.Status  //get all the statuses associated to this invoice 
    where i.ProjectID == projectid 
      //add here any more where clausole you need 
    select i //you still need invoices returned? 
).Skip(pageIndex * pageSize).Take(pageSize);