0

is there any way i can convert below syntax to LINQ equivalent.

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)
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
Kamran Pervaiz
  • 1,861
  • 4
  • 22
  • 42
  • 1
    You might have some luck with this tool http://www.sqltolinq.com/ There are several others mentioned [here](http://stackoverflow.com/questions/296972/sql-to-linq-tool) – DOK Sep 20 '11 at 15:28
  • 1
    How about having a go then showing us what you tried, Stack Overflow is not a code factory. – Kev Sep 20 '11 at 20:09

1 Answers1

1

You can use something like this:

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

For each IGrouping<DateTime, course> in the query you have the Count value, and you can also format the DateTime value of cour_date to convert mount in a string.

Mangesh
  • 3,987
  • 2
  • 31
  • 52
Massimo Zerbini
  • 3,125
  • 22
  • 22