Skip to content

Latest commit

 

History

History
43 lines (27 loc) · 1.65 KB

File metadata and controls

43 lines (27 loc) · 1.65 KB

SQL Server GROUP BY

In practice, the GROUP BY clause is often used with aggregate functions. Our basic entities do not have properties for them. A dedicated type is needed.

The simplest way is to declare a class that references the related entities and adds missing properties:

}

In EF such types are called Keyless Entity Types and they must be mapped as keyless:

modelBuilder.Entity<CustomerYearOrders>(entity => entity.HasNoKey());

Then we can introduce a dedicated DbSet<> property in the context or use ad-hoc context.Set<>() method.

Basic GROUP BY:

With aggregate:

The next few examples in the tutorial do permutations with already covered features. Except the last which has a cool SUM expression:


< BACK | HOME