-
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
Encrypted attribute convention throws exception in Select projection in EF Core 9.0.0-rc.2.24474.1 #34934
Comments
Duplicate of #34760 |
@russcam thanks for the repro, I could indeed see the regression between 8.0 and 9.0. However, this has nothing to do with MemberMemberBinding - the cause is having a value converter which captures (closure). This has already been fixed for GA in #34760 - if you try the latest EF daily build, the problem goes away (I tried with 9.0.0-rtm.24514.19). Regardless, thanks again for reporting (regardless of it ending up being a duplicate) - this is exactly the kind of report we need to make sure we're not regressing, etc. For reference, here's the narrowed-down standalone repro I produced from your original repro above: Narrowed-down reproawait using var context = new AppDbContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
var users = await context.Users
.Select(u => u.Encrypted)
.ToListAsync();
public class AppDbContext : DbContext
{
public DbSet<User> Users { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer("Server=localhost;Database=test;User=SA;Password=Abcd5678;Connect Timeout=60;ConnectRetryCount=0;Encrypt=false")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>(b =>
{
b.Property(u => u.Encrypted).HasConversion(x => Foo(x), x => Foo(x));
b.HasData(new User { UserId = 1, Encrypted = "some value" });
});
}
// Adding static to the below makes the error go away
public string Foo(string value) => value;
}
public class User
{
public int UserId { get; set; }
public string Encrypted { get; set; } = default!;
} |
Thanks for taking the time to review @roji! |
My pleasure! |
Here's a minimal repro: https://github.com/russcam/efcore9-bug
Background
The EF Core configuration uses a convention to encrypt properties in the EF model that are attributed with an
EncryptedAttribute
.This is done in an
IModelFinalizingConvention
by setting a value converter for those attributed propertiesProblem
When projecting an encrypted property in a
.Select(...)
projection such asthe following exception is thrown in EF Core 9.0.0-rc.2.24474.1
Observations
alice
entity).Include provider and version information
EF Core version: 9.0.0-rc.2.24474.1
Database provider: Sqlite in the minimal repro, but also observe it with Postgres provider. It looks to be a core issue and not provider specific.
Target framework: net9.0
Operating system: Windows 11
The text was updated successfully, but these errors were encountered: