Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automapper tries to map private class #105

Open
doerig opened this issue Oct 18, 2011 · 8 comments
Open

Automapper tries to map private class #105

doerig opened this issue Oct 18, 2011 · 8 comments

Comments

@doerig
Copy link

doerig commented Oct 18, 2011

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
    {
    }
}
@chester89
Copy link
Collaborator

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

@jagregory
Copy link
Collaborator

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.

@chester89
Copy link
Collaborator

I'll get to it

@chester89
Copy link
Collaborator

it seems to me that ability to map private non-nested classes was intended, but private nested classes wasn't

chester89 added a commit to chester89/fluent-nhibernate that referenced this issue Sep 3, 2012
@chester89
Copy link
Collaborator

I've got a question - does this change need to be reflected in documentation somewhere?

@chester89
Copy link
Collaborator

I think I got it working - but one test fails, it says public nested class shouldn't be automapped by default

chester89 added a commit to chester89/fluent-nhibernate that referenced this issue Sep 3, 2012
@jagregory
Copy link
Collaborator

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.

@chester89
Copy link
Collaborator

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

chester89 added a commit to chester89/fluent-nhibernate that referenced this issue Sep 6, 2012
chester89 added a commit to chester89/fluent-nhibernate that referenced this issue Oct 11, 2012
chester89 added a commit to chester89/fluent-nhibernate that referenced this issue Oct 11, 2012
chester89 added a commit to chester89/fluent-nhibernate that referenced this issue Oct 11, 2012
stackh34p pushed a commit to stackh34p/fluent-nhibernate that referenced this issue Sep 26, 2021
stackh34p pushed a commit to stackh34p/fluent-nhibernate that referenced this issue Sep 26, 2021
stackh34p pushed a commit to stackh34p/fluent-nhibernate that referenced this issue Sep 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants