开发者

Fluent NHibernate join table mapping

Reverse engineering an existing database to map with N-Hibernate using Fluent N-Hibernate.

How can I map this?

Address table

Id

Address1

Address2

Person table

Id

First

Last

Types

Id

TypeName

PersonAddress table (A person can have home, business etc addresses)

Id

PersonId (Id from person table)

AddressId (Id from address table)

TypeId (Id from types lookup table HOME, BUSINESS etc..)

Any help would be great. Thanks

Here's another tricky one in addition to above mapping. Don't know how easy it would be to map it.

Party Table

I开发者_开发技巧d Person Id points to Person

Identifiers Tables

Id Party Id Type Id Identifier value

Employee table

Employee Id No party or person table has foreign key to this table. The employee id is stored in the identifiers table. so for e.g. The identifier table is used store values for different types. The identifiers for a given party could DriverLicense, EmployeeId, SSN, Credit Card numeber etc, this could be many values.

Sample identifier data

Id, PartyId, TypeId, IdentifierValue

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

I am trying to get my head around this and just can't get it to mapped.


// 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜