-
Notifications
You must be signed in to change notification settings - Fork 257
Closed as not planned
Description
EF Core 7.0 introduced support for value convertors on generated properties (docs, dotnet/efcore#11597), but we don't seem to support that.
Make sure it works for all our value generation strategies (identity, HiLo (#2431), sequence).
Code sample
await using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();
ctx.Blogs.Add(new Blog { Name = "foo" });
await ctx.SaveChangesAsync();
ctx.ChangeTracker.Clear();
var blog = ctx.Blogs.Single();
Console.WriteLine(blog.Id.Value);
public class BlogContext : DbContext
{
public DbSet<Blog> Blogs { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseNpgsql(@"Host=localhost;Username=test;Password=test")
.LogTo(Console.WriteLine, LogLevel.Information)
.EnableSensitiveDataLogging();
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Blog>()
.Property(b => b.Id)
.UseIdentityAlwaysColumn()
.HasConversion(i => i.Value, v => new BlogId { Value = v });
}
}
public class Blog
{
public BlogId Id { get; set; }
public string? Name { get; set; }
}
public class BlogId
{
public int Value;
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels