0

複数の結合を使用した 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を使い始めたばかりなので、これを行う方法がわかりません。

私を案内してください。

ありがとう

4

1 に答える 1

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,
    };
于 2012-07-20T04:39:48.583 に答える