How to Execute Select Count and Group Query in Entity Framework

As the title implies we will try to convert a native sql that group and counts the number of row. We will assume that you have a column quantity or number of items.
//native query
select count(*), field
from table
group by field

//entity framework
var query = model.GroupBy(p => p.Field).Select(o => new { o.Key, Count = o.Sum(p => p.Quantity) });

0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post
NERV Open Source

Building production Spring Boot systems?

Explore NERV — open-source Java libraries for audit trails, persistence, exception handling, and reliable event-driven architecture.

Explore NERV on GitHub →