我有表地址和许多帐户表。 如何为这种情况编写Fluent映射一对一关系?
+----------+
| Address |
+----------+
| Id | PK
+----------+
+----------+
| AccountA |
+---------+
| Id | PK
| AddressId| FK
+----------+
+----------+
| AccountB |
+---------+
| Id | PK
| AddressId| FK
+----------+
答案 0 :(得分:1)
这是自动映射。
.Override<Address>(mapping => mapping.HasOne(address => caddress.AddressA).Cascade.All().LazyLoad())
.Override<Address>(mapping => mapping.HasOne(address => caddress.AddressB).Cascade.All().LazyLoad())
.Override<AddressA>(mapping => mapping.Id(x => x.Id).GeneratedBy.Foreign("Address"))
.Override<AddressB>(mapping => mapping.Id(x => x.Id).GeneratedBy.Foreign("Address"))
.Override<AddressA>(
mapping => mapping.HasOne(
Reveal.Member<AddressA, Address>("Address")).Constrained().ForeignKey().LazyLoad())
.Override<AddressB>(
mapping => mapping.HasOne(
Reveal.Member<AddressB, Address>("Address")).Constrained().ForeignKey().LazyLoad())
所有这些表都有相同的密钥:Id
+----------+
| Address |
+----------+
| Id | PK
+----------+
+----------+
| AccountA |
+---------+
| Id | PK
+----------+
+----------+
| AccountB |
+---------+
| Id | PK
+----------+