Convention for IList<Address>, IList<Email> and IList<Phone> to create new table with OneToMany.

22 views
Skip to first unread message

Riderman Sousa

unread,
May 23, 2013, 10:57:54 AM5/23/13
to Fluent NHibernate Group

In several classes of my domain have a list of emails, addresses and phone numbers;

Then I define a class for this:


public class Email : IEntity
{

    public virtual int Id { get; protected set; }
    public virtual string AddressText { get; set; }

}

public class Address : IEntity
{
    public virtual int Id { get; protected set; }
    public virtual string AddressText { get; set; }
    public virtual string City { get; set; }

    public virtual string Country { get; set; }

}

public class Phone : IEntity
{
    public virtual int Id { get; protected set; }
    public virtual string Number { get; set; }
}

In my domain I have several classes that have e mails, phone numbers and addresses. Like:

This is one among several others;


public class Company : IEntity
{
    public virtual int Id { get; protected set; }

    public virtual string Name { get; set; }

    public virtual string WebSite { get; set; }

    public virtual IList<Phone> Phones { get; protected set; }
    public virtual IList<Address> Addresses { get; protected set; }
    public virtual IList<Email> Emails { get; protected set; }

    public Company ()
    {
        Phones = new List<Phone>();

        Addresses = new List<Address>();
        Emails = new List<Email>();
    }
}

I would like to configure NHibernate to create a table (example: CompanyEmails) for each class;
In this case for example, it generated a table for Company and three other tables, CompanyEmails, CompanyPhones and CompanyAddress.

This same process would be applied for example to the class person:


public class Person : IEntity
{
    public virtual int Id { get; protected set; }

    public virtual string Name { get; set; }

    public virtual IList<Phone> Phones { get; protected set; }
    public virtual IList<Address> Addresses { get; protected set; }
    public virtual IList<Email> Emails { get; protected set; }

    public Company ()
    {
        Phones = new List<Phone>();

        Addresses = new List<Address>();
        Emails = new List<Email>();
    }
}

I know I can use IAutoMappingOverride for this. But it would have to do for each class.

How do I apply convention for all properties of type IList<Emails>to create a table.


Thanks.

Riderman de Sousa Barbosa

Web Developer | MCPD Certify

Skype.: 4042-6002 | Cel.: (31) 8681-1986

bindsolution.com

Microsoft Parner Network


Reply all
Reply to author
Forward
0 new messages