EntityFramework-Extensions icon indicating copy to clipboard operation
EntityFramework-Extensions copied to clipboard

WhereBulkContains method supports checking Ids for multiple fields

Open pvarets00101 opened this issue 1 month ago • 3 comments

It's throwing an error now "Oops! only 1 key name is currently supported." Code:

var ids = new List<string> {"id1", "Id2"};
entities.WhereBulkContains(ids, new List<string> {"Field1", "Field2"});

Is support for such functionality being considered?

pvarets00101 avatar Oct 30 '25 11:10 pvarets00101

Hello @pvarets00101 ,

You currently have a list of strings but are trying to use two keys.

The code already works if your list contains entities, for example:

var list = new List<Inventory>() { new Inventory() { ID = 1, ColumnInt = 0 } };
var results = context.Inventories.WhereBulkContains(list, new List<string>() { "ID", "ColumnInt" }).ToList();

So, if you need to map the same value to multiple keys, you can use something like an anonymous type and duplicate the value instead of a simple list of strings.

Best Regards,

Jon

JonathanMagnan avatar Oct 30 '25 14:10 JonathanMagnan

Hello @JonathanMagnan Thanks for the answer.

Yes, I know there is such a way, but creating a new List<Inventory>() { new Inventory() { ID = 1, ColumnInt = 0 } } with more than 10k entries is too expensive. I know that the WhereBulkContains method supports the following functionality

var items = dbContext.Set<TEntity>()
                .WhereBulkContains(ids, propertyName)
                .ToList();

At the time of execution, I only have a List ids, which can contain thousands of values, and I would like to be able to pass a list of ids to the WhereBulkContains method and check ids for multiple fields.

var propertyNames = new List<string> { "Id", "ParentId", ...};
var items = dbContext.Set<TEntity>()
                .WhereBulkContains(ids, propertyNames)
                .ToList();

I would like such functionality. Maybe I don't fully understand.

pvarets00101 avatar Oct 31 '25 07:10 pvarets00101

Hello @pvarets00101 ,

You’re probably also looking for an OR condition instead of an AND, such as Field1 = id OR Field2 = id.

If that’s the case, unfortunately, we currently don’t support this scenario. We have a lot of new features planned for 2026, but for now, this specific case isn’t supported. We’ll make sure to add your request to our backlog.

Best Regards,

Jon

JonathanMagnan avatar Oct 31 '25 15:10 JonathanMagnan