【发布时间】:2012-07-11 10:26:51
【问题描述】:
这是我的多个连接的 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
};
在查询中,我已经评论了我想要添加的内容以及在 Select 中评论的内容。从 BookedArea 表中,我想获取每个 invoiceID 的最小租赁日期。
我刚开始使用 LINQ,所以不知道该怎么做。
请指导我。
谢谢
【问题讨论】:
标签: linq entity-framework linq-to-sql c#-4.0