fluent nhibernate truncate string automatically

前端 未结 1 1097
耶瑟儿~
耶瑟儿~ 2021-01-22 00:08

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

相关标签:
1条回答
  • 2021-01-22 00:48

    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.

    0 讨论(0)
提交回复
热议问题