views:

50

answers:

4

Given the database design below how would you model it? Address Type is Bussiness/Home etc and the PersonId is on Address table is because there are many addresses for one Person.

I would most do something like:

public class Person
{
   public virtual int PersonId { get; set; }
   public virtual string FirstName { get; set; } 
   public virtual string LastName{ get; set; }
   public virtual DateTime DOB{ get; set; }
   public virtual IList<Address> Addresses { get; set; }
}


public class Address
{
   public virtual int AddressId{ get; set; }
   public virtual Person Resident{ get; set; }
   public virtual AddressType Location{ get; set; }
   public virtual string PostalCode{ get; set; }
   public virtual string FullAddress{ get; set; }
}

public class AddressType
{
   public virtual int AddressTypeId{ get; set; }
   public virtual string Description{ get; set; }
   public virtual IList<Address> Addresses { get; set;}
}

however I have no idea if this is appropriate. I have always done my models with objects and have never left int's in place. NHibernate Mapping will easily replace these with the objects and then lazy/eager load them, so I just figure this is the best option. Opinions?

Database Design

A: 

I would model it like it is in reality, Person has several addresses and each can be of a different type, leaving out all the database id fields. That will make your NHibernate Configurations and queries a little bit harder to create, but your domain model will be much easier to work with.

Per-Frode Pedersen
+1  A: 

The domain looks clean.

The only think I'd think twice about is the renaming of some property/column names, which can lead to confusion.

Diego Mijelshon
A: 

I suggest convert relations Address-Person and Address-AddressType to on way relations. It not very usable if each Address now its Person (resident) and each AddressType now its Address (addresses). By doing this your will be very simpler.

Additionally it seems meaningless to have a unique person for each address. Imagine you are saving some persons in your model that they are just one family that all together live in an one home. Consequently all of them have same address.

afsharm
A: 

I would change the Address and AddressType many to one relationship. It is actually one-to-one and in which case, AddressType would go in the Address table as a field. That is the best form IMHO.

0A0D