LINQ TO SQL 日期问题
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.TruncateTime(a.OperDate) into g
select g.Key