2012-07-11 5 views
0

여러 개의 조인이 포함 된 내 LINQ 쿼리는 다음과 같습니다.let LINQ 쿼리를 사용하는 방법은 무엇입니까?

잘 작동하지만 작업을 향상시켜야합니다.

var selectedResults= 
    from InvoiceSet in Invoices 
    join BookedAreaSet in BookedAreas on InvoiceSet.InvoiceID equals BookedAreaSet.InvoiceID 
    join AreaSet in Areas on BookedAreaSet.AreaID equals AreaSet.AreaID 
    join ContactSet in Contacts on InvoiceSet.ContactID equals ContactSet.ContactID 
    join Contacts_ObjectsSet in Contacts_Objects on ContactSet.ContactID equals Contacts_ObjectsSet.ContactID 
    join CompanySet in Companies on Contacts_ObjectsSet.ObjectReferenceID equals CompanySet.CompanyID 
    join Customer_CustomerGroupSet in Customer_CustomerGroup on Contacts_ObjectsSet.ObjectReferenceID equals Customer_CustomerGroupSet.CustomerID 
    join CustomerGroupDiscountsSet in CustomerGroupDiscounts on Customer_CustomerGroupSet.CustomerGroupID equals CustomerGroupDiscountsSet.ID 
    join InvoiceStatusSet in InvoiceStatus on InvoiceSet.InvoiceStatusID equals InvoiceStatusSet.ID 
    where Contacts_ObjectsSet.ObjectReference=="Company" 
//let minDate=(BookedAreaSet.LeasedDate).Min() where BookedAreaSet.InvoiceID=InvoiceSet.InvoiceID 
    select new {licensee=(CompanySet.CompanyName),CustomerGroupDiscountsSet.CustomerGroup,AreaSet.Location,InvoiceSet.InvoiceNumber,InvoiceSet.Amount,InvoiceSet.TotalDiscount,InvoiceSet.GST, 
    Paid=(InvoiceSet.InvoiceStatusID==2 ? "Paid":"UnPaid"), 
    datePaid=(InvoiceSet.PaymentDate),InvoiceSet.PaymentDate//,miDate 



    }; 

질의에서 나는 선택하고 덧붙이기를 원하는 내용을 덧붙였다. BookedArea 테이블에서 모든 invoiceID에 대해 최소 임대 날짜를 얻고 싶습니다.

저는 LINQ를 사용하기 시작 했으므로 이것을 수행하는 방법을 모릅니다.

안내해주세요.

감사

답변

0

이 시도 :

var selectedResults= 
    from InvoiceSet in Invoices 
    join BookedAreaSet in BookedAreas on InvoiceSet.InvoiceID equals BookedAreaSet.InvoiceID 
    join AreaSet in Areas on BookedAreaSet.AreaID equals AreaSet.AreaID 
    join ContactSet in Contacts on InvoiceSet.ContactID equals ContactSet.ContactID 
    join Contacts_ObjectsSet in Contacts_Objects on ContactSet.ContactID equals Contacts_ObjectsSet.ContactID 
    join CompanySet in Companies on Contacts_ObjectsSet.ObjectReferenceID equals CompanySet.CompanyID 
    join Customer_CustomerGroupSet in Customer_CustomerGroup on Contacts_ObjectsSet.ObjectReferenceID equals Customer_CustomerGroupSet.CustomerID 
    join CustomerGroupDiscountsSet in CustomerGroupDiscounts on Customer_CustomerGroupSet.CustomerGroupID equals CustomerGroupDiscountsSet.ID 
    join InvoiceStatusSet in InvoiceStatus on InvoiceSet.InvoiceStatusID equals InvoiceStatusSet.ID 
    where Contacts_ObjectsSet.ObjectReference == "Company" 
    join BookedAreaSet2 in BookedAreas on InvoiceSet.InvoiceID equals BookedAreaSet.InvoiceID into BookedAreas2 
    let minDate = BookedAreas2.Select(ba2 => ba2.LeasedDate).Min() 
    select new 
    { 
     licensee = CompanySet.CompanyName, 
     CustomerGroupDiscountsSet.CustomerGroup, 
     AreaSet.Location, 
     InvoiceSet.InvoiceNumber, 
     InvoiceSet.Amount, 
     InvoiceSet.TotalDiscount, 
     InvoiceSet.GST, 
     Paid = InvoiceSet.InvoiceStatusID == 2 ? "Paid" : "UnPaid", 
     datePaid = InvoiceSet.PaymentDate, 
     InvoiceSet.PaymentDate, 
     minDate, 
    }; 
관련 문제