Querying Entity Model. Part 21 – Intersect And Except

SQL Server and LINQ both have some commands that operates on sets like Union, Intersect and Except. I’ve investigated the behavor of Union in Entity Framework earlier in my post Querying Entity Model. Part 15 – Union. Now let’s look at intersect and except.

I want to see the intersection between two sets of country codes taken from Clients and Phones tables (I use the same simple EF model through all the Querying Entity Model series).

Wow! Entity Framework uses exactly INTERSECT operator. Well done.

Except case is similar to intersect one.

I used a collection with one field, but EF is capable to operate on collections with many fields. The only thing you should care about is to intersect/except the collections of the same type.

Leave a Reply

Your email address will not be published. Required fields are marked *