Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在这个带有连接的LINQ查询中使用Min和Max函数?_C#_Linq_Entity Framework_Linq To Sql_C# 4.0 - Fatal编程技术网

C# 在这个带有连接的LINQ查询中使用Min和Max函数?

C# 在这个带有连接的LINQ查询中使用Min和Max函数?,c#,linq,entity-framework,linq-to-sql,c#-4.0,C#,Linq,Entity Framework,Linq To Sql,C# 4.0,我正在进行一个LINQ查询,它是多个表的连接。在结果集中,我想在表格中添加一列,显示最小和最大日期组合[例如(2012年3月20日-2012年4月25日)] 我想从中选择日期的表(管理多对多关系的表)的结构如下所示: BookedAreaID int AreaID int LeasedDate datetime InvoiceID int 以下是我的LINQ查询: var selectedResults= from InvoiceSet in Invoices join Book

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

我想从中选择日期的表(管理多对多关系的表)的结构如下所示:

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)

似乎你在这个条件下加入了两次顺便说一句:

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

你就不能用它吗

DateRange=
(Min(BookedAreasSet.LeasedDate) 
+ "-" + 
Max(BookedAreasSet.LeasedDate))
您可以这样做: