我为我的实体设置了一个RowVersion列,但似乎在创建或更新时它没有存储任何内容。
在DbContext的OnModelCreating
中有以下配置:
modelBuilder.Entity<Author>()
.Property(a => a.RowVersion)
.IsConcurrencyToken()
.ValueGeneratedOnAddOrUpdate();
然而,即使在实体更新/创建之后,RowVersion列始终为NULL。
顺便说一下,我正在使用Npgsql库(NuGet)的PostgreSQL。文档中提到,PostgreSQL不支持添加或更新时的计算值。
这是造成它无法工作的原因吗?
如果是,我们为什么可以规避这个限制?
此外,我已经进行了测试:
modelBuilder.Entity<Author>().Property<byte[]>("RowVersion")
.HasColumnName(ShadowPropertiesDb.RowVersion)
.IsRowVersion();
它导致了相同的问题。
RowVersion
属性的类型是什么?如果它是byte[]
,您是否尝试过使用.IsRowVersion()
而不是.IsConcurrencyToken().ValueGeneratedOnAddOrUpdate()
? - Ivan Stoev