-
Notifications
You must be signed in to change notification settings - Fork 78
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
Map property to column xmin #382
Conversation
The column "xmin" is a default hidden column for every table in PostgreSQL. In order to use the concurrency feature, the best is to map a property to this auto-updating column. If it is just done as described in the docs now, with a random column name mapped to type 'xid', the column value remains at its default 0 on insert and upate.
I noticed, that doing this leads to the following error message when using .Distinct() since apparently the DISTINCT operation is not supported on columns of type xid:
|
@asymetrixs why are you suggesting this change? The docs in their current state already show how to map to |
Can you open an issue for this with a minimal repro on https://github.com/npgsql/efcore.pg? |
@roji I opened this issue, because either I am doing something wrong or .IsRowVersion() does not work as expected. I pushed an example to https://github.com/asymetrixs/NpgsqlTest |
@asymetrixs there's various code in your sample, so I just threw together a minimal console program based on the docs, and it works: await using var context = new BlogContext();
await context.Database.EnsureDeletedAsync();
await context.Database.EnsureCreatedAsync();
context.SomeEntities.Add(new());
await context.SaveChangesAsync();
context.ChangeTracker.Clear();
var entity = await context.SomeEntities.SingleAsync();
Console.WriteLine(entity.Version);
public class BlogContext : DbContext
{
public DbSet<SomeEntity> SomeEntities { 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<SomeEntity>()
.Property(b => b.Version)
.IsRowVersion();
}
}
public class SomeEntity
{
public int Id { get; set; }
public uint Version { get; set; }
} Try working with that to understand what the difference is, and if you think there's a problem, please file a bug in https://github.com/npgsql/efcore.pg. In the meantime I'll go ahead and close this issue as the docs are correct, and if there's any bug it should be fixed, rather than updating the docs. |
The column "xmin" is a default hidden column for every table in PostgreSQL. In order to use the concurrency feature, the best is to map a property to this auto-updating column. If it is just done as described in the docs now, with a random column name mapped to type 'xid', the column value remains at its default 0 on insert and upate.