EF Core WhereBulkContains with Entity Framework Extensions

The EF Core WhereBulkContains method from the Entity Framework Extensions library allows you to filter a LINQ query by including all items from an existing list.

For example, imagine you have a list of Customer objects where the CustomerID and a few other properties are already populated. You want to retrieve those customers from the database so you can update their values.

The WhereBulkContains method lets you filter entities based on what’s in your list:

language-csharp
|
// @nuget: Z.EntityFramework.Extensions.EFCore
using Z.EntityFramework.Extensions;

var dictDeserializedCustomers = deserializedCustomers.ToDictionary(x => x.CustomerID);

using (var context = new EntityContext())
{
    var customers = context.Customers.WhereBulkContains(deserializedCustomers).ToList();

    customers.ForEach(x =>
    {
        var deserializedCustomer = dictDeserializedCustomers[x.CustomerID];

        x.Code = deserializedCustomer.Code;
        x.Email = deserializedCustomer.Email;
        x.FirstName = deserializedCustomer.FirstName;
        x.LastName = deserializedCustomer.LastName;
    });

    // context.SaveChanges();
    context.BulkSaveChanges();
}

This method also works with batch operations like DeleteFromQuery and UpdateFromQuery, making it even easier to use in those scenarios:

language-csharp
|
// @nuget: Z.EntityFramework.Extensions.EFCore
using Z.EntityFramework.Extensions;

var dictDeserializedCustomers = deserializedCustomers.ToDictionary(x => x.CustomerID);

using (var context = new EntityContext())
{
    context.Customers.WhereBulkContains(deserializedCustomers).DeleteFromQuery();

    context.Customers
           .WhereBulkContains(deserializedCustomers)
           .UpdateFromQuery(x => new Customer { IsActive = false });
}

This unique method is part of a professional library made by ZZZ Projects. Entity Framework Extensions is the most popular and complete EF Core library available, with over 50 million downloads and more than 5,000 paid customers.


πŸ› οΈ Take Full Control of EF Core Bulk Operations

Custom keys, conditional updates, selected columns, and more. EF Extensions offers 100+ options to customize how your entities are saved.

Explore Bulk Operations →

πŸš€ Why Use the WhereBulkContains Method from Entity Framework Extensions?

Most developers use the standard Where + Contains combo to filter data in EF Core.

It works fine… until it doesn’t. Here are some common limitations:

  • ❌ Only supports basic types like int or Guid
  • ❌ Limited by SQL parameter count (you can’t pass too many IDs)
  • ❌ Doesn’t support composite keys or other complex scenarios

That’s where the WhereBulkContains method from Entity Framework Extensions really shines β€” it was built to overcome all of these limitations:

  • βœ… Supports any kind of data source

    • βœ… Basic types like List<int> or List<Guid>
    • βœ… Entity types like List<Customer>
    • βœ… Anonymous types (e.g., new { ID = 1 })
    • βœ… Even ExpandoObject lists
  • βœ… Handles an unlimited number of items

  • βœ… Works with surrogate keys and composite keys

No matter how complex your list is, WhereBulkContains makes filtering just work β€” and scale.


πŸ“¦ How to Install Entity Framework Extensions

To use the WhereBulkContains method, install the Z.EntityFramework.Extensions.EFCore NuGet package:

language-powershell
|
PM> NuGet\Install-Package Z.EntityFramework.Extensions.EFCore
language-bash
|
> dotnet add package Z.EntityFramework.Extensions.EFCore

Entity Framework Extensions uses EF Core pinned versioning, so make sure the first digit of the package version matches your EF Core version. For example:

  • If you're using EF Core 10, use version v10.x.y.z
  • If you're using EF Core 9, use version v9.x.y.z
  • If you're using EF Core 8, use version v8.x.y.z
  • And so on...

Looking for a different version, like WhereBulkContains for EF6? πŸ‘‰ Download it here


βœ… Final Thoughts

When it comes to filtering large datasets in EF Core, the WhereBulkContains method from Entity Framework Extensions is a powerful tool you shouldn’t overlook.

It works with any data source, supports unlimited items, and handles complex scenarios that the standard Where + Contains method just can’t. Whether you're working with basic ID lists or full entities, this method helps you write cleaner, faster, and more efficient queries.

Give it a try and see how much smoother your data filtering can be!


Looking for more resources? Here are some helpful links to learn more about the WhereBulkContains method and Entity Framework Extensions, explore its documentation, and download the right version for your project.

πŸ“˜ Documentation

πŸ“¦ Downloads & Packages


Date Modified: 2025-11-11
Author:

Edit this page in GitHub

Got any EF Core Question?