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

linq返回值处理的问题
请问大家
我写了一个linq的方法
C# code

       public IQueryable GetList()
        {
            var query = from accountInfo in _AccountDBDataContext.AccountInfo
                    group accountInfo by new
                    {
                        accountInfo.Category
                    } into g
                    select new
                    {
                        SumAmount = g.Sum(p => p.Amount),
                        g.Key.Category
                    };
            return query;
        }



返回的是IQueryable 
绑定到gridview上显示是这样的

SumAmount Category 
403.0000 吃饭 
144.0000 交通 
113.0000 旅行 
1000.0000 其他 
66.5000 饮料 
4634.0000 娱乐 

问题是,我想把这些数据,SumAmount输出成一个字符串数组,Category 也输出成一个字符串数组
不知道应该怎么做啊

------解决方案--------------------
var list = query.ToList();//先执行查询
list.Select( item => item.Category ).ToArray();

另外一个类似。
------解决方案--------------------
不会,帮你顶一下
------解决方案--------------------
再遍历一遍返回的 query 用两个list<string>存起来不行么?