I would refer to your original model and question. So it would basically be
implemented something like this:
*Entity*
public abstract class EntityBase
{
public Guid Id { get; set; }
}
public class Employee : EntityBase
{
public Employee()
{
this.Addresses = new Collection<EmployeeAddress>();
}
public ICollection<EmployeeAddress> Addresses { get; set; }
public string FullName { get; set; }
}
public enum AddressType
{
Home,
Office
}
public class EmployeeAddress : EntityBase
{
public EmployeeAddress()
{
this.AddressType = AddressType.Home;
}
public Address Address { get; set; }
public AddressType AddressType { get; set; }
public Employee Employee { get; set; }
}
public class Address : EntityBase
{
public string AddressLine { get; set; }
}
*Entity Mapping*
public class EmployeeMap : ClassMap<Employee>
{
public EmployeeMap()
{
this.Id(x => x.Id)
.GeneratedBy.GuidComb()
.UnsavedValue("00000000-0000-0000-0000-000000000000");
this.Map(x => x.FullName);
this.HasMany(x => x.Addresses)
.KeyColumn("EmployeeId")
.Cascade.AllDeleteOrphan()
.Fetch.Join()
.Inverse();
}
}
public class EmployeeAddressMap : ClassMap<EmployeeAddress>
{
public EmployeeAddressMap()
{
this.Id(x => x.Id)
.GeneratedBy.GuidComb()
.UnsavedValue("00000000-0000-0000-0000-000000000000");
this.References(x => x.Employee)
.Column("EmployeeId")
.Cascade.SaveUpdate();
this.References(x => x.Address)
.Column("AddressId")
.Cascade.SaveUpdate()
.Fetch.Join();
this.Map(x => x.AddressType);
}
}
public class AddressMap : ClassMap<Address>
{
public AddressMap()
{
this.Id(x => x.Id)
.GeneratedBy.GuidComb()
.UnsavedValue("00000000-0000-0000-0000-000000000000");
this.Map(x => x.AddressLine);
}
}
Here's EmployeeAddress is the linking table (or entity) between Employee
and Address. That way you can have a single address references by many
other entities (Employee, Customer, etc.).
Also notice, there's an AddressType property in it. It's needed to define
the type of the address. So for example, this way you can have a single
address used as home address, office address, delivery address, etc.
On Tue, Apr 23, 2013 at 9:12 PM, Peter Forstmeier <
[email protected]> wrote:
> Hi,
> would you be that kind and give me a example how to map:
> EmployeeHomeAddress
> EmployeeBussinessAddress
>
> CustomerHomeAddress
> CustomerBillingAddress
>
> ProjectDeliveryAddress
>
> Thanks in advance
> Peter
>
>
> On 23 Apr., 13:38, Peter Forstmeier <[email protected]>
> wrote:
> > > Hi,
> > > would you be that kind and give me a small sample about this kind of
> > > mapping
> >
> > > So to speak:
> > > EmployeeHomeAddress
> > > EmployeeBusinessAddress
> >
> > > CustomerBillingAddress
> > > CustomerHomeAddress
> >
> > > and so on for projects etc
> > > all should map to Address
> >
> > > Peter
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
Regards,
Maximilian Haru Raditya
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.