2011-09-20 59 views
0

有什么办法可以将以下语法转换为LINQ等效。将SQL转换为等效LINQ

select DateName(month , DateAdd(month , month(cour_date) , 0) - 1),count(*) 
from course 
where cour_date>CONVERT(varchar, YEAR(GETDATE())) + '-01' + '-01' 
and cour_deleted is null and cour_type='Group' 
group by month(cour_date) 
order by month(cour_date) 
+1

您可能对此工具有一定的运气http://www.sqltolinq.com/还有其他几个人提到[这里](http://stackoverflow.com/questions/296972/sql-to-linq-tool) – DOK

+1

如果你去尝试一下,然后向我们展示你的想法,Stack Overflow不是一个代码工厂。 – Kev

回答

1

您可以使用这样的事情:

var query = from c in course 
      where c.cour_date > DateTime.Parse("2011-01-01") 
       && c.cour_deleted == null && c.cour_type.Equals("Group") 
      orderby c.cour_date 
      group c by c.cour_date.Month 

对于你的计数值查询每个IGrouping<DateTime, course>,你也可以格式化cour_date的日期时间值,以安装转换成字符串。