2010-06-02 117 views
2

反向工程現有的數據庫使用Fluent N-Hibernate映射到N-Hibernate。流利的NHibernate連接表映射

如何映射此?

地址表

標識
地址1
地址2

Person表

標識
首先
最後

類型

標識
類型名

PersonAddress表(一個人可以擁有家庭,企業等地址)

標識

PERSONID(編號從人表)

AddressId(編號從地址表)

TypeId(來自類型查找表主頁,商業等的Id)

任何幫助都會很棒。謝謝

除了上面的映射,這是另一個棘手的問題。不知道映射它有多容易。

黨表

標識 人員標識指向人

標識表

標識 方ID 類型標識 標識值

Employee表

員工ID號黨或人t能夠擁有這張表的外鍵。員工ID存儲在 標識符表中。所以對於例如標識符表用於存儲不同類型的值。給定方的標識符可以是DriverLicense,EmployeeId,SSN,Credit Card等等,這可能是很多值。

樣本標識符數據

標識,PartyId,TYPEID,IdentifierValue

1,1,1,EMPLID-1234 2,2,1,EMPLID-4567 3,3,1,EMPLID- 34354

我試圖讓我的頭在這個,只是無法得到它映射。

回答

4
// this answer assumes you have functional Address, Person, Type, and PersonAddress objects. 

public class AddressMap : ClassMap<Address> 
{ 
    public AddressMap() 
    { 
    Id(x=>x.Id); 
    Map(x=>x.Address1); 
    Map(x=>x.Address2); 
    } 
} 

public class PersonMap : ClassMap<Person> 
{ 
    public PersonMap() 
    { 
    Id(x=>x.Id); 
    Map(x=>x.First); 
    Map(x=>x.Last); 
    } 
} 

public class TypeMap : ClassMap<Type> 
{ 
    public TypeMap() 
    { 
    Id(x=>x.Id); 
    Map(x=>x.TypeName); 
    } 
} 

public class PersonAddressMap : ClassMap<PersonAddress> 
{ 
    public PersonAddressMap() 
    { 
    Id(x=>x.Id); 
    References(x=>x.Person, "PersonId"); 
    References(x=>x.Address, "AddressId"); 
    References(x=>x.Type, "TypeId"); 
    } 
} 
+0

這很好用!感謝你的幫助。 – Rusty 2010-08-12 12:22:40

+0

但是這實際上並沒有加入表格,所以你的表現仍然會受到打擊,因爲它正在爲每個子對象進行單獨的查詢。 – Nexxas 2013-02-12 15:58:32