EF Core Where Bulk Contains

Entity Framework Extensions provides the WhereBulkContains extension method that allows you to filter a LINQ query by including all items from an existing list.

For example, you have a list of Customer with the CustomerID and a few other properties populated. Then you want to retrieve those authors from the database to update those properties.

The WhereBulkContains method will filter entities to include those contained in the list.

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;



Date Modified: 2023-03-02

Edit this page in GitHub

Got any EF Core Question?