Nhibernate流利布尔到smallint映射 [英] nhibernate fluent bool to smallint mapping

查看:120
本文介绍了Nhibernate流利布尔到smallint映射的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我有一个名为DisplayIndi​​cator的bool属性.在数据库(DB2)中,它的对应关系是smallint类型的DISPL_IND列. 对应关系如下: [DisplayINdicator = True,DISPL_IND = 1]和 [DisplayINdicator = False,DISPL_IND = 0] 是否可以使用nhibernate fluence将bool属性映射为smallint?

In my application I have a bool property named DisplayIndicator. In the database (DB2) it's correspondence is DISPL_IND column of type smallint. The correspondence is the following: [DisplayINdicator=True, DISPL_IND=1] and [DisplayINdicator=False, DISPL_IND=0] Is it possible to map using nhibernate fluence the bool property to smallint?

推荐答案

在Frans的建议下,我弄清楚了. 我创建了一个表示nhibernate用户类型的类,该类用于将布尔类型映射为短类型:

I figured it out, after Frans's advise. I created a class that represents nhibernate user type used to map boolean type to short type:

公共类BooleanAsShortType:IUserType

public class BooleanAsShortType : IUserType

向映射添加了一个CustomType属性,现在它看起来像这样:

To the mapping, I added a CustomType property and now it looks like this:

Map(x => x.DisplayIndi​​cator,"DSPL_IND").CustomType< BooleanAsShortType>();

Map(x => x.DisplayIndicator, "DSPL_IND").CustomType< BooleanAsShortType >();

这篇关于Nhibernate流利布尔到smallint映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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