1

我正在做一个 LINQ 查询,它是多个表的连接。在结果集中,我想在表格中添加一个同时显示最小和最大日期的列[例如(20/3/2012 - 25/4/2012)]

我想从中选择日期的表(这是一个管理多对多关系的表)的结构如下:

BookedAreaID    int
AreaID  int
LeasedDate  datetime
InvoiceID   int

这是我的 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 BookedAreasSet in BookedAreas on InvoiceSet.InvoiceID equals BookedAreasSet.InvoiceID

where Contacts_ObjectsSet.ObjectReference=="Company"

select new {InvoiceSet.InvoiceNumber,InvoiceSet.Amount,InvoiceSet.TotalDiscount,InvoiceSet.GST,
InvoiceSet.PaymentDate,InvoiceSet.ShoppingCentreID,BookedAreasSet.BookedAreaID,AreaSet.Name,Paid=(InvoiceSet.PaymentDate==null ? "UnPaid":"Paid"), 
licensee=(CompanySet.CompanyName))
};

我想用这个查询选择类似的东西:

DateRange=
(Min(BookedAreasSet.LeasedDate where BookedAreasSet.InvoiceID=InvoiceSet.InvoiceID) 
+ "-" + 
Max(BookedAreasSet.LeasedDate where BookedAreasSet.InvoiceID=InvoiceSet.InvoiceID)
4

1 回答 1

0

好像你在这种情况下加入了两次顺便说一句:

“在 InvoiceSet 上的 BookedAreas 中加入 BookedAreasSet。InvoiceID 等于 BookedAreasSet.InvoiceID”

不能随便用吗?

DateRange=
(Min(BookedAreasSet.LeasedDate) 
+ "-" + 
Max(BookedAreasSet.LeasedDate))
于 2012-07-11T13:03:26.320 回答