Tuesday, December 20, 2011

Multipal Field Group By IN LINQ


var objOrderList = from OL in
        (from OrderDetail in objOrderDetail
      join Item in objItem on OrderDetail.ItemId equals Item.ItemId
      join ItemGroup in objItemGroup on Item.GroupId equals ItemGroup.GroupId
      select new
      {
       GroupName = ItemGroup.GroupName,
       ItemName = Item.ItemName,
       Rate = Item.Rate,
       Qty = OrderDetail.Qty
      }
      )
       group OL by new
       {
        OL.GroupName,
        OL.ItemName
       } into OrderList
       select new
       {
        GroupName = OrderList.Key.GroupName,
        ItemName = OrderList.Key.ItemName,
        OrderTotal = OrderList.Sum(OL => OL.Qty * OL.Rate)
       };

No comments:

Post a Comment