I’ve been trying to migrate from NHibernate 2.3 to 3.2, including moving from Fluent NHibernate 1.0 to 1.3.
After doing the upgrade, the Fluent conventions picked up by searching the assemblies don’t appear to be applied; I get numerous errors complaining about not being able to find certain properties or columns.
Edit:
My mapping setup looks like this:
.Mappings(
m => m.FluentMappings
.AddFromAssemblyOf<NHibernateMapping>()
.Conventions.AddFromAssemblyOf<NHibernateMapping>())
I’ve managed to get the fluent interface to load all the conventions with a breakpoint on their constructors to track when they’re initialized. However, none of the conventions are actually being called: none of the breakpoints in their Apply methods are being hit.
The error manifests through NHibernate is as follows:
NHibernate.MappingException: Could not find a setter for property ‘All’ in class ‘Headline’
The property All does not have a setter – one of the conventions should change the mapping to refer to the setter on a different property.
On examination of the HBM files being exported, I can see that none of the conventions have been applied and the default Fluent conventions are being used.
Why are my conventions not being applied to the mapping?
Edit:
Through trial-and-error, I’ve found that the problem lies in the AddFromAssemblyOf<T>() call. The mapping system is finding and initializing each of the IConvention types, but then does not add them to the visitor and does not apply them to the mapping.
A workaround discovered is to add each convention manually with the Add<TConvention>() call. This works for us because we have a handful of conventions. It wouldn’t take much effort to write an extension method to replace AddFromAssemblyOf<T>(), if somebody required a more robust work-around to the problem.
Still unsure why this doesn’t work, but it feels like a bug now.
We are using 1.3 and use an extension method to add all of our conventions like so: