**Table Order**
Id (PK)
NonUniqueId
**Table OrderLine**
Id (PK)
OrderNonUniqueId
Text
I have a legacy database where there OrderLine references Order via non primary key. A Order Line may belong to many Orders.
How can this be mapped at HasMany?
**OrderMap**
HasMany(x => x.OrderLines)
.KeyColumn("OrderNonUniqueId")
(will not work since it uses the primary key Order.Id)
Have you tried using PropertyRef
?
public OrderMap()
{
...
Map(x => x.NonUniqueId);
HasMany<OrderLine>(x => x.Lines)
.KeyColumn("OrderNonUniqueId")
.PropertyRef("NonUniqueId");
...
}
It seems the extra Map
is necessary otherwise fluent nhibernate complains. If you map the one-to-many within an hbm.xml file the extra property mapping for the NonUniqueId
isn't required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With