首页 新闻 会员 周边 捐助

EF,linq group by 不能分组,郁闷,查遍文档,请高手帮看一下

0
悬赏园豆:5 [待解决问题]

我的表是这样的。

SELECT TOP 1000 [VODID]
      ,[VODName]
      ,[VODLocation]
      ,[VODSets]
      ,[VODDesc]
      ,[ProgramFlag]
      ,[TypeID]
      ,[GroupID]
      ,[GroupName]
      ,[TypeName]
      ,[Threshold]
  FROM [WASUP1V1].[dbo].[V_VODInfo]

这是个视图。

想按VODID来分组,结果失败。

代码是这样的:

 int     alldatacount = entities.V_VODInfo.GroupBy(a => a.VODID).Count();

得到的结果总是和没有分组前的总是一样的,郁闷,请高手讲解。

最后我写成这样,数据映射成内存对象才能分组,但这样数据量大时会浪费内存。是这样理解吗?

int alldatacount = entities.V_VODInfo.AsQueryable().ToList().GroupBy(a => a.VODID).Count();

dzswwsg的主页 dzswwsg | 初学一级 | 园豆:195
提问于:2010-11-20 17:31
< >
分享
所有回答(1)
0
  List<FWorkBills> fw = new List<FWorkBills>();
fw.Add(new FWorkBills { WorkState = "完工", date = new DateTime(2011, 2, 1, 0, 0, 0) });
fw.Add(new FWorkBills { WorkState = "完工", date = new DateTime(2011, 2, 2, 0, 0, 0) });
fw.Add(new FWorkBills { WorkState = "评估", date = new DateTime(2011, 3, 1, 0, 0, 0) });
fw.Add(new FWorkBills { WorkState = "评估", date = new DateTime(2011, 3, 2, 0, 0, 0) });
fw.Add(new FWorkBills { WorkState = "评估", date = new DateTime(2011, 3, 3, 0, 0, 0) });
fw.Add(new FWorkBills { WorkState = "未完工", date = new DateTime(2011, 4, 1, 0, 0, 0) });
fw.Add(new FWorkBills { WorkState = "未完工", date = new DateTime(2011, 4, 2, 0, 0, 0) });
fw.Add(new FWorkBills { WorkState = "未完工", date = new DateTime(2011, 4, 3, 0, 0, 0) });
fw.Add(new FWorkBills { WorkState = "未完工", date = new DateTime(2011, 4, 4, 0, 0, 0) });

var Query = from p in fw
group p by p.WorkState[0] into g
select new
{
工程状态 = g.Key,
数量 = g.Count(),
日期=string.Format("{0:yyyy年MM月dd日}", g.ElementAt(0).date)
};
this.bindingSource1.DataSource = Query;
this.dataGridView1.DataSource = this.bindingSource1
幕三少 | 园豆:1384 (小虾三级) | 2013-08-12 14:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册