efcore icon indicating copy to clipboard operation
efcore copied to clipboard

EF Core 3.0 can not load a List of entities, when using a hashset

Open dietrichha opened this issue 7 years ago • 1 comments

Hi,

I'm using ef core 3.0 now and get errors where ef core 2.1 was doing everthing okay.

I have two Entities: A and B, A can have multiple Bs

var aIDs = ListOfBs.Select(b => b.aID)).ToHashSet();

var listOfA = await _context.A .AsNoTracking() .Where(a => aIDs .Contains(a.ID)) .ToListAsync();

Now I get here an Error! However If I change the Code to:

var aIDs = ListOfBs.Select(b => b.aID)).ToHashSet().ToList();

var listOfA = await _context.A .AsNoTracking() .Where(a => aIDs .Contains(a.ID)) .ToListAsync();

The Code works again. Could it be that we cannot use HashSets in a where statement with ef core 3.0 ?

I'm using the HashSet to get rid of duplicate IDs. In the original programm I can have mutiple duplicate IDs of A ...

dietrichha avatar Nov 16 '19 17:11 dietrichha

Duplicate of #17342

ajcvickers avatar Nov 16 '19 18:11 ajcvickers