[英]C# Entity Framework Grouping
我有一个附表,其数据如下所示...
ScheduleID | CustomerID | SubdivisionID | LotNumber | ProductID | ProductDate
1 1 1 5555 1 11/7/2015
2 1 1 5555 2 11/8/2015
3 1 1 5555 3 11/9/2015
4 2 1 7777 1 11/7/2015
5 2 1 7777 2 11/8/2015
6 2 1 7777 3 11/9/2015
我需要一个C#Linq To Entities查询,该查询返回按行将所有Product Dates按CustomerID,SubdivisionID,LotNumber分组的数据。
因此,例如,我需要看到这样的数据...
CustomerID | SubdivisionID | LotNumber | ProductDate1 | ProductDate2 | ProductDate3
1 1 5555 11/7/2015 11/8/2015 11/9/2015
2 1 7777 11/7/2015 11/8/2015 11/9/2015
我相信这涉及到一些分组和联接,但是我对实体框架组不太满意。 我的代码在这里应该是什么样?
我正在按照这些思路思考...
var context = new ScheduleEntities();
from c in context.Schedule
where c.ProductID == 1 || c.ProductID == 2 || c.ProductID = 3
group c by new { c.CustomerID, c.SubdivisionID, c.LotNumber } into grouped
select new {
CustomerID = grouped.Key.CustomerID,
SubdivisionID = grouped.Key.SubdivisionID,
LotNumber = grouped.Key.LotNumber,
ProductDates = **some kind of List<> ??**
}
如您所见,我对如何将所有产品日期都放入匿名实体感到困惑。 我该怎么办?
也许您可以使用此ProductDates = grouped.Select(p => p.ProductDate)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.