I want to convert this SQL query to Linq in C#:
select
count(*),
FORMAT (CreatedDate, 'MM') as months,
FORMAT (CreatedDate, 'yyyy') as year
from
ProviderPosts
group by
FORMAT (CreatedDate, 'MM'),
FORMAT (CreatedDate, 'yyyy')
I want to convert this SQL query to Linq in C#:
select
count(*),
FORMAT (CreatedDate, 'MM') as months,
FORMAT (CreatedDate, 'yyyy') as year
from
ProviderPosts
group by
FORMAT (CreatedDate, 'MM'),
FORMAT (CreatedDate, 'yyyy')
2
Answers
The following code is an almost exact translation of your query, however depending on the LINQ provider it may not be able to translate it to SQL.
Try to do not convert to anything. Use
.Year
and.Month