数据库包含订单.订单可以包含在一组订单中.对于每组订单,它可以包含1到多个订单.
但是,Orders可以为NULLO值分配GroupOrderId,因为之前的Orders没有分组概念.只有新订单强制执行添加到组的概念.
要为每个订单执行操作而要填充的类结构是
public class OrdersGroup
{
public int? GroupOrderId { get; set; }
public List<int> OrderIds { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
linq声明
var workPacketOrdersList = (from o in db.Orders
where
o.GroupOrderId >= groupOrderIdMin && o.GroupOrderId <= groupOrderIdMax &&
o.IsDeleted == false
orderby o.WorkPacketId ascending
group o by o.WorkPacketId
into grp
select new OrdersGroup
{
GroupOrderId = grp.Key,
OrderIds = grp.Select(g => g.OrderId).ToList()
}).ToList();
Run Code Online (Sandbox Code Playgroud)
完全例外
LINQ to Entities does not recognize the method 'System.Collections.Generic.List`1[System.Int32] ToList[Int32](System.Collections.Generic.IEnumerable`1[System.Int32])' method, and this method cannot …Run Code Online (Sandbox Code Playgroud)