我如何告诉 NHibernate 将 FK 空字符串视为 NULL?
我正在处理一个具有一些“有趣”结构的遗留数据库。我有一个表“Operation”,其中有一个名为“PersonnelID”的可为空字符串列。该列指向一个名为“Personnel”的表,该表具有整数主键列。当 PersonnelID 列是表示为字符串或 NULL 的整数时,NHibernate 没有问题,但当该列包含空字符串(或任何其他与此相关的内容时,它就会崩溃。虽然这是有道理的,但我想让它足够聪明,可以识别何时可以使用“PersonnelID”值来加载相关人员以及何时将该值视为垃圾。 看起来像 IUserType,但不完全是。
I'm working off a legacy database with some "interesting" structures. I have a table "Operation" with a nullable string column called "PersonnelID". This column points to a table called "Personnel" with an integer primary key column. NHibernate has no problem when the PersonnelID column is either an integer represented as a string or NULL, but it blows up when that column contains an empty string (or anything else for that matter. While this makes sense, I'd like to make it smart enough to recognize when a "PersonnelID" value can be used to load the related Personnel and when to treat the value as garbage. Where would I inject my logic? Seems like a IUserType, but not quite.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在多对一上设置
not-found="ignore"
属性。从文档中:You can set the
not-found="ignore"
attribute on the many-to-one. From the documentation: