Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Contains fails with using a IReadOnlySet #26437

Closed
Grauenwolf opened this issue Oct 22, 2021 · 4 comments · Fixed by #26487
Closed

.Contains fails with using a IReadOnlySet #26437

Grauenwolf opened this issue Oct 22, 2021 · 4 comments · Fixed by #26487
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported good first issue This issue should be relatively straightforward to fix. type-enhancement
Milestone

Comments

@Grauenwolf
Copy link

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

@ajcvickers
Copy link
Member

@smitpatel to find dupe.

@smitpatel
Copy link
Member

No dupe, need to update following method

public static bool IsContainsMethod(this MethodInfo method)
=> method.Name == nameof(IList.Contains)
&& method.DeclaringType != null
&& method.DeclaringType.GetInterfaces().Append(method.DeclaringType).Any(
t => t == typeof(IList)
|| (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ICollection<>)));

IReadOnlyCollection doesn't derive from ICollection causing us to fail in this case.

@smitpatel smitpatel added area-query type-enhancement good first issue This issue should be relatively straightforward to fix. labels Oct 26, 2021
@ajcvickers
Copy link
Member

@smitpatel Related to #26433 or not?

@smitpatel
Copy link
Member

Not related. #26433 is on navigation property which is readonly collection. This one is client side object being readonly collection.

@ajcvickers ajcvickers modified the milestone: 7.0.0 Oct 26, 2021
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 28, 2021
@smitpatel smitpatel removed the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 28, 2021
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 28, 2021
@ghost ghost closed this as completed in #26487 Nov 1, 2021
ghost pushed a commit that referenced this issue Nov 1, 2021
@ajcvickers ajcvickers modified the milestones: 7.0.0, 7.0.0-preview1 Feb 14, 2022
@ajcvickers ajcvickers modified the milestones: 7.0.0-preview1, 7.0.0 Nov 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported good first issue This issue should be relatively straightforward to fix. type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants