nhibernate,外键列中为 0
我有一个遗留数据库,其中 FK 列中使用值 0 来指示未指定任何关系。
这不是我可以通过微不足道的方式改变的。是否可以告诉 NHibernate 将指定列中的 0 视为 null?
编辑
我知道not-found
,但我只想忽略那些带有0的。
I got a legacy database where the value of 0 was used in FK columns to indicate that no relation have been specified.
This is not something that I can change in a trivial way. Is it possible to tell NHibernate to treat 0 as null in specified columns?
Edit
I know about not-found
, but I just want to ignore those with 0.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个解决方案对我们来说非常有用:http://nhibernate.info/blog/2011/01/28/how-to-use-0-instead-of-null-for-foreign-keys.html
简而言之:
添加以下类:
然后为每个相关映射注册它:
This solution worked great for us: http://nhibernate.info/blog/2011/01/28/how-to-use-0-instead-of-null-for-foreign-keys.html
In short:
Add the following class:
Then register it for every relevant mapping:
还有一个类似的问题: NHibernate Saving 0 to多对一列而不是 null。诺埃尔·肯尼迪提出了一个有趣但有点奇怪的解决方案。
我可能会在数据库中存储一条 ID 为 0 的记录,它代表一个空对象。
There is a similar question: NHibernate Saving 0 to many-to-one column instead of null. There is an interesting, but a bit weird solution by Noel Kennedy.
I would probably store a record with the ID 0 in the database, which represents a Null Object.