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

HashSet<enum>.Contains could not be translated #17877

Closed
IgorMenshikov opened this issue Sep 17, 2019 · 3 comments
Closed

HashSet<enum>.Contains could not be translated #17877

IgorMenshikov opened this issue Sep 17, 2019 · 3 comments

Comments

@IgorMenshikov
Copy link

IgorMenshikov commented Sep 17, 2019

I have a quite simple table named Operation and class for it. It has a property named Type mapped to an enum:

[Column("OperationTypeID")]
public OperationType.Code Type { get; set; }

I try to request all operations with a filter by type and other fields:

var list = (from i in context.Operation
                        where typeList.Contains(i.Type) &&
                            i.DeleteDate == null &&
                            i.PeriodID == parameters.PeriodID
                        orderby i.PlanDate descending
                        select new L.Item()
                        {
                            Operation = i
                        }).ToList();

List of necessary types is stored at the HashSet<OperationType.Code> typeList variable.

On 2.2. this query works OK. On 3.0.0-rc1 it fails with an error:

System.InvalidOperationException: 'The LINQ expression 'Where<Operation>(
    source: DbSet<Operation>, 
    predicate: (o) => HashSet<Code> { Submission, Reset, Calculate, ESIPaymentReport, Retraction, RetractionUndo, MoveRecord, MoveRecordUndo, CVSCAG, BIUpdate, }.Contains(o.Type) && o.DeleteDate == null && o.PeriodID == (Unhandled parameter: __parameters_PeriodID_0))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync().

If I change HashSet to List, the query works.

Can HashSet be translated as List for queries?

Further technical details

EF Core version: 3.0.0-rc1.19456.14
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.3 Preview 4

@smitpatel
Copy link
Contributor

Possibly same root cause as #17342

@alexmurari
Copy link
Contributor

HashSet<T>.Contains implements ICollection<T>.Contains so it really is the same root cause as #17342.

This is fixed on 3.1.0 by #17599.

@IgorMenshikov
Copy link
Author

thanks for the information. will wait till 3.1.0 to try again.

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

No branches or pull requests

4 participants