views:

89

answers:

2

Fluent NHibernate is currently unable to use the IParameterizedType of a CustomType but I need to use the fluent mapping because I want to adjust the mapping within my code.

Is there a workaround for Fluent NHibernate that somehow injects the XML elements that would be used within the normal mapping XML-file?

I did already find the similar SO Question "Fluent Nhibernate problem (ClassMap)" but the given answer doesn't seem to work with Fluent NHibernate 1.0.

A: 

Since a fix for your issue exists in the latest Fluent NHibernate, but not in 1.0 (as illustrated by Fluent Nhibernate problem (ClassMap), you should be using that version instead.

See the Getting Started guide, under the section "Getting the source", for instructions on getting the latest version.

Alternatively, you can map this one class with a traditional *.hbm.xml file, while your other classes are mapped with fluent nhibernate. Example:

var sessionFactory = Fluently.Configure()
    .Database(...)
    .Mappings(m =>
    {
        m.FluentMappings.AddFromAssemblyOf<...>();
        m.HbmMappings.AddFromAssemblyOf<...>();
    })
    .BuildSessionFactory();
Daniel Schilling
I checked out the source at http://fluent-nhibernate.googlecode.com/svn/trunk/ but even grep is unable to find a function called AddAlteration. Have you tried the example code yourself or am I missing something?
Martin
I apologize. I assumed that the functionality was still there. I've looked at the source code too now and confirmed that it's not there anymore. My second suggestion, "m.HbmMappings...", should still be valid, though.
Daniel Schilling
As I mentioned in my question, I want to generate the mapping within the code. So a static XML based mapping file is no alternative for me.
Martin
From James Gregory: "It was removed because we no longer generate XML in the interface, instead we're generating a proper object model. Passing around XML chunks is seriously bad form.I'd rather people spend time actually implementing the missing features than hacks."
Daniel Schilling
So it seems like there are a few options. 1) You can use a static XML file. It's more of a problem to maintain, but it will work. 2) You can get a specific version of fluent-nhibernate which still has this functionality. It was removed on April 22, 2009, so the version from April 21 should work. 3) You can implement the "param" feature in your own github fork. This would be super cool because it would benefit all of us.
Daniel Schilling
A: 

I need to use the fluent mapping because I want to adjust the mapping within my code.

You don't necessarily need to use the fluent mapping to adjust the mapping withing your code. NHibernate supports dynamic mapping.

Here is an example of dynamic mapping in NHibernate.

Nik