日期:2014-05-17 浏览次数:20419 次
from a in DB group a by
new
{
Date = a.OperDate.Date
//或Date = EntityFunctions.CreateDateTime(a.OperDate.Year,...)
}
var GroupTotal = ( from a in DB
group a by new { a.LoginBrower } into g
select new
{
g.Key.LoginBrower,
newnum = g.Count()
}).ToList();
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() }; });
from a in DB
group a by EntityFunctions.Trunc