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

9.0 should set collection translation to use constants #1955

Closed
kanadaj opened this issue Dec 11, 2024 · 4 comments · Fixed by #1971
Closed

9.0 should set collection translation to use constants #1955

kanadaj opened this issue Dec 11, 2024 · 4 comments · Fixed by #1971

Comments

@kanadaj
Copy link

kanadaj commented Dec 11, 2024

EF Core 9.0 supports Parameterized Collections, but Pomelo seems to throw on trying to translate it. It requires setting TranslateParameterizedCollectionsToConstants() in the options for any queries involving .Where(x => myCollection.Contains(x.Field)) to work at all. Might be best to set it by default to make upgrades smoother until it's fixed.

Setting it by default in general might be best in order to preserve current behaviour so it's an opt-in with TranslateParameterizedCollectionsToParameters() instead

@roji
Copy link

roji commented Dec 11, 2024

@kanadaj regardless of your issue, note that EF 10 will likely switch back to inlining constants for parameterized collections by default, since that generally produces better query plans (see dotnet/efcore#34347). But generally the same technical infrastructure is also relevant for collection columns (e.g. a column containing a JSON array of ints), so this is still relevant.

@benjaminoerskov
Copy link

Im getting this error
The LINQ expression 'v.UserIds' could not be translated. Additional information: Primitive collections support has not been enabled. 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.

Even though I have TranslateParameterizedCollectionsToConstants() set. I also tried setting EnablePrimitiveCollectionsSupport(), but that didnt change anything either. Any help on this? Im on Pomelo.EntityFrameworkCore.MySql Version=9.0.0-preview.2.efcore.9.0.0.

My setup:

 services.AddDbContext<TContext>(delegate (DbContextOptionsBuilder options)
 {
     options.UseMySql(MySqlContainerFixture.ConnectionString, new MySqlServerVersion("8.0.26"), options =>
     {
         options
             .TranslateParameterizedCollectionsToConstants() // <-- uses EF.Constant() for all collections - Needed to enable "Primitive collections" https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/1960
             .EnableRetryOnFailure();
     });

     options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
 });

@lauxjpn
Copy link
Collaborator

lauxjpn commented Jan 7, 2025

@benjaminoerskov If calling TranslateParameterizedCollectionsToConstants() does not fix your issue, than this issue here is not the one you are experiencing. Therefore, open a new new one, and post some code (including the query you are trying to execute), so we can reproduce your issue. Thanks!

@benjaminoerskov
Copy link

@lauxjpn Thanks for your reply. I was trying to access a list of guids, but my migration created it as a string. I think thats the reason I couldnt get it to work. I resolved it by moving my data to a new table instead.

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