Fluent Nhibernate mapping to avoid null references
We have an Order
entity and a CreditCard
entity.
The Order
can have 0 or 1 CreditCards
.
The CreditCard
can ha开发者_StackOverflow中文版ve 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?
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.
精彩评论