-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Enum ICollection Contains => TRUE = FALSE #23059
Comments
Which provider and EF Core version? |
@ErikEJ |
/cc @roji for PostgreSQL |
As far as I can tell, there's nothing PostgreSQL-specific in the code above - the enum array/list is value-converted to a database string field (i.e. no usage of native PostgreSQL enums). However, if you use Npgsql.EntityFrameworkCore.PostgreSQL 5.0.0-rc2 and remove the value conversion, everything will work just fine: await using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
var group = MessageGroup.SomeGroup;
_ = await ctx.Users
.Where(x => !x.IsSoftDeleted && (x.MessageGroups.Contains(group) || x.MessageGroups.Contains(MessageGroup.ALL)))
.ToListAsync();
public class BlogContext : DbContext
{
public DbSet<User> Users { get; set; }
static ILoggerFactory ContextLoggerFactory
=> LoggerFactory.Create(b => b.AddConsole().AddFilter("", LogLevel.Information));
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseNpgsql(@"Host=localhost;Username=test;Password=test")
.EnableSensitiveDataLogging()
.UseLoggerFactory(ContextLoggerFactory);
}
public class User
{
public int Id { get; set; }
public bool IsSoftDeleted { get; set; }
public List<MessageGroup> MessageGroups { get; set; }
}
public enum MessageGroup
{
ALL,
SomeGroup
} SQL: SELECT u."Id", u."IsSoftDeleted", u."MessageGroups"
FROM "Users" AS u
WHERE NOT (u."IsSoftDeleted") AND (u."MessageGroups" @> ARRAY[@__group_0]::integer[] OR u."MessageGroups" @> ARRAY[0]::integer[])
|
On main branch, I am not seeing any such SQL. We accurately generate translation failure error as we cannot translate Contains over a string column in database. |
Hello,
i have a bug or need some help with my code.
await context.Users.Where(x => !x.IsSoftDeleted && (x.MessageGroups.Contains(group) || x.MessageGroups.Contains(MessageGroup.ALL))).ToListAsync();
With this code EfCore generate this SQL:
So why the Contains generate TRUE = FALSE ?
Databasefield has this Conversion:
entity.Property(e => e.MessageGroups).HasConversion(v => string.Join(',', v), v => v.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(x => x.ToEnum<MessageGroup>()).ToList());
Can someone help me. Thanks!
The text was updated successfully, but these errors were encountered: