views:

118

answers:

1

Example:

public class ContactMap : ClassMap<Contact>
{
    public ContactMap()
    {
        WithTable("ida_contact");
        Id(x => x.ID, "ida_contact_id").WithUnsavedValue(0).GeneratedBy.UuidHex("");
        Map(x => x.FirstName);
        Map(x => x.Surname);
        Map(x => x.Address1, "dm_address_1");
        Map(x => x.Address2, "dm_address_2");
        Map(x => x.Address3, "dm_address_3");
        Map(x => x.Postcode, "dm_postcode");
        Map(x => x.City, "dm_city");
        Map(x => x.CountryCode, "dm_countrycode");
        Map(x => x.PhoneMobile, "phone_mobile");
        Map(x => x.PhoneHome, "phone_home");
        Map(x => x.Email);
        Map(x => x.DOB);
        Map(x => x.SMSAccept, "sms_accept");
        Map(x => x.EmailAccept, "email_accept");
        Map(x => x.UserName);
        Map(x => x.Password);
    }
}

This class-mapping is to restrictive as the table will look completely different in some of my other projects.

What I'm inclined to do is map a dictionary where each element in the dictionary represents a column in the table, that way it will be 100% dynamic with regard to adding columns in the database, and I would only need to update the mappingfile with which table to use if I'm integrating versus a different system. This would also require a table with metadata to supply type and validation info to satisfy the requirements for my domain.

Is there any way to do this mapping in fluent-nhibernate? Some form of

public class ContactMap : ClassMap<IDictionary<string, object>>
{
     WithTable("Current_contactTable");
}

I do think the solution smells a bit bad tough, so if anyone has a more strongly typed solution or a link to one id love to hear it ;).

A: 

I don't think there is, you should create a new mapping.

This class-mapping is to restrictive as the table will look completely different in some of my other projects.

Well it's another project, another mapping. The point of fluentNH is to create a strongly typed way of writing mapping files - that's it.

Your dictionary wouldn't improve anything , wouldn't you have to rewrite the data in the dictionary too ? (or maybe I misunderstood something.)

sirrocco