我使用EF 4和c#,MS SQL 2008。
我有一个T-SQL:
select COUNT(*)
from CmsContents
where IsPublished = 1 and isDeleted = 0
GROUP BY Day(Date)
我需要将它转换为EF,但我无法得到它。
我正在使用的是:
var contentsByMonth = context.CmsContents
.Where(c => c.IsPublished == true & c.IsDeleted == false)
.GroupBy(c => c.Date.Month).ToList().Count();
你能举个例子吗?感谢
答案 0 :(得分:1)
var contentsByMonth = context.CmsContents
.Where(c => c.IsPublished == true & c.IsDeleted == false)
.GroupBy(c => c.Date.Day)
.Select(g => new {Day = g.Key, Counts = g.Count()})
.ToList();