Skip to content

.Contains fails with using a IReadOnlySet #26437

Closed

Description

File a bug

.Contains fails with using a IReadOnlySet.

Include your code

To fix any bug we must first reproduce it. To make this possible, please attach a small, runnable project or post a small, runnable code listing that reproduces what you are seeing.

It is often impossible for us to reproduce a bug when working with only code snippets since we have to guess at the missing code.

Use triple-tick code fences for any posted code. For example:

IReadOnlySet<int> searchIds = [...] 
var result = persons.Where(p => p.Locations.Any(l => searchIds.Contains(l.Id)));

A work-around is to explicitly cast it to the IEnumerable<int> base interface.

IReadOnlySet<int> searchIds = [...] 
var temp = (IEnumerable<int>)searchIds;
var result = persons.Where(p => p.Locations.Any(l => searchIds.Contains(l.Id)));

Include stack traces

Include the full exception message and stack trace for any exception you encounter.

Use triple-tick fences for stack traces. For example:

    .Where(s => __searchIds_0.Contains(l.Id))' could not be translated. Additional information: Translation of method 'System.Collections.Generic.IReadOnlySet<int>.Contains' failed. If this method can be mapped to your custom function, see https://go.microsoft.com/fwlink/?linkid=2132413 for more information. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.


Include provider and version information

EF Core version: 5.0.10
Database provider: Microsoft.EntityFrameworkCore.SqlServer 5.0.10
Target framework: .NET 5.0
Operating system: Windows 10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

area-queryclosed-fixedThe issue has been fixed and is/will be included in the release indicated by the issue milestone.customer-reportedgood first issueThis issue should be relatively straightforward to fix.type-enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions