流畅的 Nhibernate 映射以避免空引用
我们有一个 Order
实体和一个 CreditCard
实体。
订单
可以有 0 或 1 个信用卡
。
CreditCard
可以有 1 个或多个 Orders
我理解这是一对多关系。但我们预计大多数订单
不会使用信用卡
支付,因此订单表将充满空引用。我的理解是这是一个不好的做法。
是否可以通过其他方式设计数据库/实体/映射来避免这种情况?
We have an Order
entity and a CreditCard
entity.
The Order
can have 0 or 1 CreditCards
.
The CreditCard
can have 1 or more Orders
I understand this to be a one-to-many relationship. BUT we anticipate for the majority of Orders
to not be paid using a CreditCard
, hence the Order table will be full of null references. My understanding being that this is a bad practice.
Is it possible to design the database/entities/mappings some other way to avoid this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你想多了。如果是我,我只会在我的订单中引用信用卡,而在我的信用卡实体中,我将有一个 HasMany 到订单。如果您愿意,可以在订单中添加 HasCreditCard 布尔值,仅检查订单中的信用卡对象是否为空。
I think that you are over thinking this. If it were me I would just have a Reference to a credit card in my order and in my credit card entity I would have a HasMany to Orders. If you want you can have a HasCreditCard boolean in your order that just checks if the credit card object in your order is null or not.