2010-06-02 127 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