NHibernate字符串属性的length属性 [英] NHibernate string property length attribute

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

问题描述

所以我有一个具有以下属性的NHibernate映射文件:

So I have an NHibernate mapping file with the following property:

<property name="FullName" column="FullName" type="string" not-null="true" />

例如,如果我将length ="50"设置为,NHibernate将在插入数据库时​​截断字符串.如果删除length属性,则该数据库将引发异常,就像应该的一样;说它不能插入记录.这是正常行为吗?如果是这样,那么length属性的目的是什么.也许我没有正确配置NHibernate或不了解这种情况.任何想法/想法都会很棒.

If I set the length="50" for example, NHibernate will truncate the string when inserting into the database. If I remove the length property, that database throws the exception like it should; saying that it cannot insert the record. Is this normal behavior? If so, what is the purpose of the length property. Perhaps I've configured NHibernate incorrectly or am not appreciating the situation. Any thoughts/ideas would be great.

推荐答案

使用架构导出器时,Length属性用于根据模型/映射创建数据库.

Length property is used to create a database from the model/mappings when you are using schema exporter.

如果您要在持久性期间寻找字符串长度验证,请查看NHibernate.Validator项目.

If you are looking for string length validation during persistence, take a look at the NHibernate.Validator project.

http://nhforge.org/blogs/nhibernate/archive/2009/05/01/nhibernate-validator.aspx

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

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