使用Fluent N-Hibernate对现有数据库进行逆向工程以映射到N-Hibernate。
我该如何映射它呢?
地址表
Id
Address1
Address2
Person表
Id
第一
最后的
类型
Id
TypeName
PersonAddress表(一个人可以有家庭、公司等地址)
Id
PersonId (来自person表的Id)
AddressId (地址表Id)
TypeId (Id来自类型查找表HOME、业务等)
任何帮助都是最好的。谢谢
除了上面的映射之外,这里还有另一个棘手的映射。不知道映射它有多容易。
Party Table
Id人员Id指向人员
标识符表
Id参与方Id类型Id标识符值
Employee表
员工Id没有交易方或人员表具有指向此表的外键。员工id存储在标识符表中。因此,例如,标识符表用于存储不同类型的值。给定方的标识符可以是DriverLicense、EmployeeId、SSN、信用卡号码等,可以是很多值。
示例标识符数据
Id、PartyId、TypeId、IdentifierValue
1,1,1,EMPLID-1234 2,2,1,EMPLID-4567 3,3,1,EMPLID-34354
我正试着想明白这一点,但就是不能把它映射出来。
发布于 2010-06-03 18:35:47
// 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");
}
}
https://stackoverflow.com/questions/2960391
复制