fluent-nhibernate
fluent-nhibernate copied to clipboard
Automapper tries to map private class
After Upgrading from FNH 1.2 to 1.3 my project threw some runtime exceptions. It turned out that fnh 1.3 tries to map a private nested class. Is this intended behaviour or a bug?
I fixed the problem within the AutomappingConfiguration (checking for IsPublic).
public class AutomappingConfiguration : DefaultAutomappingConfiguration
{
public override bool ShouldMap(Type type)
{
return type.IsPublic && type.IsSubclassOf(typeof(ModelBase));
}
}
Simplified class-setup:
public class MappedClass : ModelBase
{
}
public class NotMappedClass
{
private class WhyDoesThisClassGetsMapped : MappedClass
{
}
}
I guess that this particular scenario just wasn't tested. But you're making a point, I think it would be a good default to use only public classes out of the box and be able to override this behaviour at will. I'll take this one in, unless someone has other suggestions
I agree, I can't see why a private nested class should be mapped by default. @chester89 if you're happy to work on this, that's great; I think it should just be a case of pulling @doerig's changes into the DefaultAutomappingConfiguration
.
I'll get to it
it seems to me that ability to map private non-nested classes was intended, but private nested classes wasn't
I've got a question - does this change need to be reflected in documentation somewhere?
I think I got it working - but one test fails, it says public nested class shouldn't be automapped by default
So with this change, no nested classes would be mapped by default?
As for docs, there isn't any mention of nested classes in the docs currently; it might be worth adding a note to the automapping wiki page when this is resolved. Just so we've got the behaviour explicitly stated somewhere.
Thanks for your help on this.
What I did is completely ignored only private nested classes when doing automapping. Public and protected nested classes are being mapped. Is this the desired behaviour? May be we should exclude protected classes also