使用XPO和LINQ实现分组查询功能.
Aug252014
Session s = ((XPObjectSpace)ObjectSpace).Session;
XPQuery<Ord_OrderMain> queryOrders = s.Query<Ord_OrderMain>();
var p = from order in queryOrders
where order.CurrentStatus == Enu_OrderStatus.WaitPrint
group order by new { Oid = order.TranShop.Oid, ShopName = order.TranShop.ShopName } into g
select new { aa = g.Count(), g.Key.Oid, g.Key.ShopName };
foreach (var item in p)
{
System.Diagnostics.Debug.WriteLine(item.ShopName + item.aa.ToString());
}
生成的SQL语句(MSSQL):
select count(*),N0.”TranShop”,N1.”ShopName” from (“dbo”.”Ord_OrderMain” N0
left join “dbo”.”Bas_OnLineShop” N1 on (N0.”TranShop” = N1.”Oid”))
where (N0.”GCRecord” is null and (N0.”CurrentStatus” = 2))
group by N0.”TranShop”,N1.”ShopName”