NHibernate 更新后更新了实体中的时间戳属性
本文关键字:更新 时间戳 属性 实体 NHibernate | 更新日期: 2023-09-27 18:37:22
我有一个利用NHibernate的 ASP.NET/SQL Server应用程序。我是 NHibernate 的新手,我在并发方面遇到了问题。
skt分配表具有Timestamp
类型的TS_tblAllocations
列。当我对sktAllocations
表执行更新时,实体中的TS_tblAllocations
属性不会更新。有没有办法告诉 NHibernate 在映射代码中更新后更新TS_tblAllocations
字段?还是需要在更新后手动从数据库中获取整个实体?
以下是用于sktAllocations
的 NHibernating XML 映射的重要部分。
<hibernate-mapping assembly="Trauma.Core"
namespace="Trauma.Core.Domain.Model" xmlns="urn:nhibernate-mapping-2.2">
<class name="Sktallocations" table="sktAllocations" lazy="true" >
<id name="Fallocationid" column="FAllocationID">
<generator class="identity" />
</id>
.
.
.
<property name="TS_tblAllocations" generated="always">
<column name="TS_tblAllocations" sql-type="timestamp" not-null="false" />
</property>
</class>
</hibernate-mapping>
我在SQL Server timestamp
中使用了相同的功能。使用 NHibernate 4+(与 3.3.+ 相同)和这样的映射 - 一切都按预期工作,在任何更新后,都会立即选择该列:
<class name="Sktallocations" table="sktAllocations" lazy="true"
optimistic-lock="version" dynamic-update="true" batch-size="25" >
<id name="Fallocationid" column="FAllocationID">
<generator class="identity" />
</id>
.
.
.
// <property name="TS_tblAllocations" generated="always">
// <column name="TS_tblAllocations" sql-type="timestamp" not-null="false" />
// </property>
<version name="TS_tblAllocations" generated="always"
unsaved-value="null" type="BinaryBlob">
<column name="TS_tblAllocations" not-null="false" sql-type="timestamp"/>
</version>
</class>
和这样的财产
public class Sktallocations
{
...
protected virtual byte[] TS_tblAllocations { get; set; }
检查文档:
- 5.1.7. 版本(可选)
也许还有
- 5.1.8. 时间戳(可选)