views:

29

answers:

2

Is this possible in fluent nhibernate having multiple mappings for one table? Lets suppose i have a Users table.

Once i want it to be apped exactly like in file UserMap1.cs, and some times I would rather prefer mapping from UserMap2.cs.

I don't need to switch configurations while app is running. I just have to choose a proper one at the beginning.

Thanks in advance:-)

A: 

This might be a hack, but you could possibly put your two mappings into separate namespaces. Then you could add mappings from either one namespace or the other depending on your needs.

Matthew Talbert
A: 

You're using Fluent NHibernate, so you're likely using the Mappings.FluentMappings object. I normally invoke AddAssemblyFrom (providing a type in the assembly containing mappings). You may need to invoke the Add or Add(Type type) method to add them invididually. My thought is to use MEF to attribute your ClassMap subclasses and add metadata in select cases to determine which ones to inject.

Rich