5. 分组操作符—【LINQ标准查询操作符】
public class GroupBy_LINQ
{
static string ContextString = System.Configuration.ConfigurationSettings.AppSettings["ContextString"].ToString();
static DataContext context = new DataContext(ContextString);
static Table<SalesOrderHeader> orders = context.GetTable<SalesOrderHeader>();
public static void GroupBy_Print()
{
var groupByQuery = orders.Where(ord => ord.SalesPersonID > 0 && ord.SalesPersonID!=null).GroupBy(ord => ord.SalesPersonID, order => order.CustomerID);
foreach (var item in groupByQuery)
{
Console.WriteLine(item.Key);
foreach (var o in item)
{
Console.WriteLine(" " + o.ToString());
}
}
Console.ReadKey();
}
public static void GroupBy_Print2()
{
// 混合语法,因为GroupBy在查询语法中不能使用
var groupByQuery = (from o in orders
where o.SalesPersonID > 0 && o.SalesPersonID != null
select o).GroupBy(ord => ord.SalesPersonID, ord => ord.CustomerID);
foreach (var item in groupByQuery)
{
Console.WriteLine(item.Key);
foreach (var o in item)
{
Console.WriteLine(" " + o.ToString());
}
}
Console.ReadKey();
}
}
【天天来(http://www.daydaycome.com)】- 精选折扣商品,爆料精选,九块九白菜底价尽在天天来!是一个中立的,致力于帮助广大网友买到更有性价比网购产品的分享平台,每天为网友们提供最受追捧 最具性价比 最大幅降价潮流新品资讯。我们的信息大部分来自于网友爆料,如果您发现了优质的产品或好的价格,不妨给我们爆料(谢绝商家)

浙公网安备 33010602011771号