nhibernate fluent bool to smallint mapping

☆樱花仙子☆ 提交于 2019-12-10 10:26:43

问题


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?


回答1:


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:

public class BooleanAsShortType : IUserType

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

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




回答2:


You could implement IUserType on a class and convert bool to short and back and apply it to the field where you need it.



来源:https://stackoverflow.com/questions/3044310/nhibernate-fluent-bool-to-smallint-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!