日期:2014-05-17  浏览次数:20387 次

LINQ TO SQL 日期问题

from a in DB group a by 
new
{
   Date = a.OperDate.Date
   //或Date = EntityFunctions.CreateDateTime(a.OperDate.Year,...)
}


上面两种方式均会报错,请问该如何正确按日期分组?

------解决方案--------------------
 c#啊不会,你应该去c语言板块看看
------解决方案--------------------
写错了。。

  var GroupTotal = ( from a in DB 
                group a by new { a.LoginBrower } into g
 select new
                                          {
                                              g.Key.LoginBrower,
                                              newnum = g.Count()
                                          }).ToList();


------解决方案--------------------
try this?
------解决方案--------------------
var list=DB.GroupBy(g=>g.OperDate).Select(t => { return new { OperDate = t.Key, count = t.Count() }; });
或者格式化日期字段:

var list=DB.Select(t => { return new { OperDate = t.OperDate.ToString("yyyy-MM-dd"), Name=t.Name }; }).ToList();  //假设Name为其中一个字段
list = list.GroupBy(g=>g.OperDate).Select(t => { return new { OperDate = t.Key, count = t.Count() }; });


------解决方案--------------------
放错地方了吧?哈哈,应该放到C#论坛模块去吧
------解决方案--------------------
from a in DB 
group a by EntityFunctions.Trunc