Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework T-Sql "having" Equivalent

How can I write a linq to entities query that includes a having clause?

For example:

SELECT State.Name, Count(*) FROM State
INNER JOIN StateOwner ON State.StateID = StateOwner.StateID
GROUP BY State.StateID
HAVING Count(*) > 1
like image 960
Jeremy Avatar asked Sep 10 '09 18:09

Jeremy


People also ask

What is LINQKit?

What is LINQKit? LINQKit is a free set of extensions for LINQ to SQL and Entity Framework power users. It comprises the following: An extensible implementation of AsExpandable() A public expression visitor base class (ExpressionVisitor)

What is EF code in SQL?

Entity Framework Core allows you to drop down to SQL queries when working with a relational database.

What is include in LINQ query C#?

LINQ include helps out to include the related entities which loaded from the database. It allows retrieving the similar entities to be read from database in a same query. LINQ Include() which point towards similar entities must read from the database to get in a single query.


1 Answers

Any reason not to just use a where clause on the result?

var query = from state in states
            join stateowner in stateowners
              on state.stateid equals stateowner.stateid
            group state.Name by state.stateid into grouped
            where grouped.Count() > 1
            select new { Name = grouped.Key, grouped.Count() };
like image 54
Jon Skeet Avatar answered Sep 20 '22 18:09

Jon Skeet