In this post, let's have a look at this small yet handy EF Core 8.0 feature
for troubleshooting concurrency issues.
Before EF Core 8.0, the rowversion property in C# classes needs to be of type byte[].
public record Post
{
public int Id { get; set; }
public string Title { get; set; }
public byte[] Timestamp { get; set; }
}
And when debugging, it looks like the following.
Now with EF Core 8.0, we can map the rowversion to long or ulong.
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Post>()
.Property(e => e.Timestamp)
.HasConversion<byte[]>()
.IsRowVersion();
}
public record Post
{
public int Id { get; set; }
public string Title { get; set; }
public long Timestamp { get; set; }
}
When debugging it's more readable now.
Regards,
Jaliya
Jaliya
No comments:
Post a Comment