Fluent Inheritance and Table-Per-Class – version 1.0.1

by Mikael Henriksson 13. August 2009 22:02

In this post I showed an old way of doing this. The new way would look like this:

public class PersonMap : ClassMap<Person>
{
  public PersonMap()
  {
    Table("person");

    Id(x => x.Id, "person_id");
    Map(x => x.FirstName, "person_first_name");
    Map(x => x.LastName, "person_last_name");
    Map(x => x.CreatedAt, "created_at");
  }
}
public class ContactMap : SubclassMap<Contact>
{
  public ContactMap()
  {
    Table("contact");

    Map(x => x.Email, "contact_email");
    Map(x => x.Phone, "contact_phone");
    Map(x => x.Mobile, "contact_mobile");

          Component(x => x.Address, c =>
                                      {
                                          c.Map(x => x.StreetOne, "address_street_one");
                                          c.Map(x => x.StreetTwo, "address_street_two");
                                          c.Map(x => x.Zip, "address_zip");
                                          c.Map(x => x.City, "address_city");
                                          c.Map(x => x.Country, "address_country");
                                      });
    References(x => x.ContactType)
      .LazyLoad()
      .Cascade.All()
      .Column("contact_type_id");
  }
}

Tags:

Fluent NHibernate

blog comments powered by Disqus

About the author

Life architect specialized in programming