1

I am new to ET Core and I am looking for a way to group by week (DateTime column) and get the counts from LINQ.

Can someone please help me to do this?

Thanks.

Ex: Need to get this same result from LINQ

Geshem W
  • 137
  • 1
  • 1
  • 10

1 Answers1

2

EF Core 2.0 doesn't implement GROUP BY.

You can use FromSql to execute a raw SQL query and map it to an entity, or you can create a VIEW and map it to an entity as if it were a table, eg :

class BlogPostCount
{
    public int BlogID{get;set;}
    public int Count {get;set;}         
}


var query = "SELECT BlogID,Count(*) as Count from BlogPosts group by BlogID";
var counts = context.BlogPostCounts.FromSQL(query).ToList();
Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236