NHibernate的3.2 code ClassMapping的版本属性 [英] NHibernate 3.2 By Code ClassMapping for Version Property

查看:177
本文介绍了NHibernate的3.2 code ClassMapping的版本属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是映射在SQL Server中时间戳列的正确方法使用NHibernate的新的code根据映射2008数据库?

What is the correct way to map an timestamp column in an SQL Server 2008 database using NHibernate's new code based mappings?

我在我的类属性定义为byte []的,我用我的ClassMapping文件中的以下映射:

I have the property in my class defined as byte[] and I'm using the following mapping in my ClassMapping file:

Version(x => x.RowVersion, mapping =>
   mapping.Generated(VersionGeneration.Always));

然而,NHibernate的期望在此基础上映射一个整数(抛出上插入一个例外)。如果我明确指定映射类型为byte []的,我得到一个异常,指出:System.ArgumentOutOfRangeException:预期类型实施IUserVersionType 参数名:persistentType

However, NHibernate is expecting an integer based on this mapping (throws an exception on inserts). If I explicitly specify the mapping type as byte[], I get an exception stating: "System.ArgumentOutOfRangeException: Expected type implementing IUserVersionType Parameter name: persistentType".

什么是正确的方法来映射新的NHibernate code根据映射自动更新timestamp列?

What is the proper way to map an auto updating timestamp column with the new NHibernate code based mappings?

---修改

我想我有缩小,我需要设置类型的映射BinaryType(一个NHibernate类型实现IVersionType),但BinaryType不具有公共构造......我想我走了想法。

I think I have it narrowed down that I need to set the Type on the mapping to BinaryType (an NHibernate Type that implements IVersionType), but BinaryType doesn't have a public constructor...I think I'm out of ideas.

推荐答案

我们还使用 byte []的版本{获得; } 的版本实施。

We also are using byte[] Version { get; } for version implementation.

下面是出于映射:

Version(x => x.Version)
            .Nullable()
            .CustomSqlType("timestamp")
            .Generated.Always()
            ;

也为更多详细信息,请参阅

这篇关于NHibernate的3.2 code ClassMapping的版本属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆