我有一个使用NHibernate的ASP.NET / SQL Server应用程序。我是NHibernate的新手,我遇到了并发问题。
sktAllocations表格的TS_tblAllocations
列属于Timestamp
类型。当我在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>
答案 0 :(得分:1)
我在SQL Server timestamp
中使用相同的功能。使用NHibernate 4+ (与3.3。+相同)和这样的映射 - 所有按预期工作,在任何 UPDATE后立即选择该列:
<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; }
检查doc:
也许