简体   繁体   English

NHibernate更新后更新实体中的时间戳属性

[英]NHibernate updated timestamp property in entity after update

I have an ASP.NET / SQL Server application that utilizes NHibernate. 我有一个利用NHibernate的ASP.NET/SQL Server应用程序。 I am a newbie to NHibernate and I am having issues with concurrency. 我是NHibernate的新手,并且在并发方面遇到了问题。

The sktAllocations table has a TS_tblAllocations column that is of a Timestamp type. sktAllocations表具有Timestamp类型的TS_tblAllocations列。 When I perform an update on the sktAllocations table the TS_tblAllocations property in the entity is not updated. 当我在sktAllocations表上执行更新时, sktAllocations中的TS_tblAllocations属性不会更新。 Is there anyway to tell NHibernate to update the TS_tblAllocations field after an update within the mapping code? 无论如何,是否要告诉NHibernate在映射代码内进行更新后更新TS_tblAllocations字段? Or do I need to manually get the whole entity from the database after an update? 还是我需要在更新后从数据库中手动获取整个实体?

Below is the important parts of the NHibernating XML mapping for sktAllocations . 以下是NHibernating XML映射中sktAllocations的重要部分。

<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>

I am using the same feature with SQL Server timestamp . 我在SQL Server timestamp使用了相同的功能。 With NHibernate 4+ (the same with 3.3.+) and mapping like this - All is working as expected, after any UPDATE there is immediate SELECT of that column : 使用NHibernate 4+ (与3.3。+相同)并像这样进行映射-一切都按预期工作,在进行任何UPDATE之后,立即对该列进行SELECT

<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>

And property like this 和这样的财产

public class Sktallocations
{
    ...
    protected virtual byte[] TS_tblAllocations { get; set; }

Check doc: 检查文件:

And maybe also 而且也许

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM