有人可以帮我转换为Linq to SQL
SELECT
a.dtCreated, COUNT(a.dtCreated)
FROM
(SELECT
CONVERT(VARCHAR(12), dtCreated, 106) AS dtCreated
FROM tblNotes) a
GROUP BY
a.dtCreated
ORDER BY
a.dtCreated
由于
答案 0 :(得分:0)
您尚未定义语言:
C#
var query = tblNotes
.GroupBy(x=>x.dtCreated)
.Select
(
x => new
{
dtCreated = x.Key.ToString("dd mmm yyyy"),
Count = x.Count()
}
)
.OrderBy(x=>x.dtCreated);
VB
Dim query = tblNotes.GroupBy(Function(x) x.dtCreated) _
.Select(Function(x) New With _
{ _
.dtCreated = x.Key.ToString("dd mmm yyyy"), _
.Count = x.Count() _
}) _
.OrderBy(Function(x) x.dtCreated)
答案 1 :(得分:0)
假设dtCreated
是datetime
且有一个您想要消除的时间组件,并进一步假设您仍希望将dtCreated
视为排序日期:
var q1 = tblNotes.GroupBy(n => n.dtCreated.Date) // Group by the Date property of this DateTime
.OrderBy(g => g.Key) // Order by the key, which is the Date portion of dtCreated
.Select(g => new
{
dtCreated = g.Key.ToString("dd mmm yyyy"),
Count = g.Count()
});