zzzprojects / EntityFramework-Extensions

Entity Framework Bulk Operations | Improve Entity Framework performance with Bulk SaveChanges, Insert, update, delete and merge for SQL Server, SQL Azure, SQL Compact, MySQL and SQLite.
https://entityframework-extensions.net
346 stars 57 forks source link

WhereBulkContains returns duplicate rows from the DB #591

Open SClifford1 opened 4 months ago

SClifford1 commented 4 months ago

Description

WhereBulkContains does not behave as I would have expected when filtering with a list containing duplicate entries. I expected filtered rows to appear at most once in the results but instead, I see rows duplicated.

This query returns a list of size 4, with Groups with ID 1 and 2 included twice. Id is the primary key of the groups table.

var targetGroups1 = await this.targetRepository.Set<Group>()
    .WhereBulkContains(( new List<int>() {1,1,2,2 } ), g => g.Id)
    .ToListAsync();

I would have expected the same behaviour as using a Contains with EF. This query returns a list of size 2, with Groups 1/2 included once.

var targetGroups2 = await this.targetRepository.Set<Group>()
    .Where(g => ( new List<int>() {1,1,2,2 } ).Contains(g.Id))
    .ToListAsync();

I can obviously work around this by providing a distinct list of Ids above but it would be good if this could be fixed all the same.

Further technical details

JonathanMagnan commented 4 months ago

Hello @SClifford1 ,

Thank you for reporting. We will look into it.

Best Regards,

Jon