问题描述
有没有一个简单的方法来自动截断字符串使用流利的nHibernate映射。我宁愿不要解决这个setters或一个自定义类型,但在映射文件中的东西。如果我正确地理解了你的话,你想确保字符串持久化到数据库的长度不能超过指定长度。这听起来像是商业上的担忧,尽管可能属于领域模型或验证逻辑。
这个问题似乎已经被问及之前的解决方案一个自定义的nHibernate UserType。请记住,这不是一个自定义的实体类型或基类,这是一个nHibernate可以理解的自定义映射类型。
如果自定义usertype解决方案不符合你的愿望,那么你可以实现一个自定义的拦截器,但我不认为有任何东西在nHibernate做这个out-of -THE盒。然而,这就是nHibernate的优点,它是非常可扩展的,并且为你的情况实现一个自定义用户类型并不难。
Is there an easy way to automatically truncate strings using fluent nHibernate mappings. I would prefer to not address this the setters or a custom type, but with something in the mapping files.
If I understand you correctly you want to make sure strings persisted to the database are no longer than a specified length. This sounds like it could be a business concern though and probably does belong in the domain model or as validation logic.
This question appears to have been asked before and the solution was a custom nHibernate UserType. Keep in mind this isn't a custom entity type or base class, this is a custom mapping type that nHibernate can understand.Automatically truncating strings in NHibernate / SQL Server
If the custom usertype solution isn't to your liking then you could implement a custom interceptor, but I don't believe there is anything in nHibernate that does this "out-of-the-box". However, that is the beauty of nHibernate is that it is very extensible and implementing a custom user type for your situation is not difficult at all.
这篇关于流利的nhibernate自动截断字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!