日期:2014-05-20  浏览次数:20742 次

动态分组查询...急...
以前有个项目,用户跟据需求,动态选择要分组的项.
后台通过组SQL语句的方式,完成动态分组求各,
现在改用LINQ TO SQL
急用啊.....

------解决方案--------------------
你学习一下linq不就行了
http://www.cnblogs.com/lovecherry/archive/2007/08/13/853754.html
------解决方案--------------------
没有具体例子,不好回答,给你看个分组的吧:

C# code
int[] scores = { 70, 81, 62, 53, 92, 85, 77, 88, 60, 83, 100, 78, 71 };
var query = from x in scores
            group x by x / 10 into g
            select string.Format("{0}~{1}分数段的人有{2}个。"g.Key, g.Key + 10, g.Count());
foreach (string item in query)
{
    Console.WriteLine(item);
}

------解决方案--------------------
晕,修改下
C# code
int[] scores = { 70, 81, 62, 53, 92, 85, 77, 88, 60, 83, 100, 78, 71 };
var query = from x in scores
            group x by x / 10 into g
            orderby g.Key
            select string.Format("{0}~{1}分数段的人有{2}个。", g.Key * 10, g.Key * 10 + 9, g.Count());
foreach (string item in query)
{
    Console.WriteLine(item);
}