Group By week - Entity Framework Core

entity-framework-core linq

Question

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

1
1
9/1/2017 9:32:31 AM

Accepted Answer

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();
2
9/1/2017 9:59:02 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow