2012-03-29 127 views
-1

我有帳戶的表地址和許多表。 如何在這種情況下編寫Fluent映射一對一關係?流利NHibernate一對一關係

+----------+ 
| Address | 
+----------+ 
| Id  | PK 
+----------+ 

+----------+ 
| AccountA | 
+---------+ 
| Id  | PK 
| AddressId| FK 
+----------+ 

+----------+ 
| AccountB | 
+---------+ 
| Id  | PK 
| AddressId| FK 
+----------+ 

回答

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()) 

所有這些表有同樣鍵:身份證

+----------+ 
| Address | 
+----------+ 
| Id  | PK 
+----------+ 

+----------+ 
| AccountA | 
+---------+ 
| Id  | PK 
+----------+ 

+----------+ 
| AccountB | 
+---------+ 
| Id  | PK 
+----------+