Automapper doesnt Map HasMany Collections which uses a backing field

Martin F's Avatar

Martin F

12 Mar, 2010 03:07 AM via web

Hello

i am using auto mapping and are trying to set Access.CamelCaseField(CamelCasePrefix.Underscore) for every HasMany collection being mapped.

I have created a Convention which Implements the IHasManyConvention interface.
In the implementation i call instance.Access.CamelCaseField(CamelCasePrefix.Underscore);

My domain for an example contains the following

private IList emails = new List();
public virtual IEnumerable Emails { get { return
emails; } }

It seems that the automapper never recognises any HasMany mappings when i change my Domain Entities to use a backing field (like shown above) and therefore the HasMany Convention is never applied.

If i use .Override(m => m.HasMany(x => x.Emails)) to manually set up the HasMany mapping on the Emails Property it works fine, but then auto mapping is beginning to get less useful and the configuration gets confusing as more and more needs to be overriden.

How can i solve this problem ?

I dont want to expose the IList soo it is possible to add items to the list from the "outside".
I want items to be added through an AddMember helper method or some other smart way which makes sure that both sides of a relationsship is set correctly.

Martin

  1. Support Staff 2 Posted by James Gregory on 12 Mar, 2010 09:28 AM

    James Gregory's Avatar

    Currently, you can't. The automapper is very opinionated and inflexible, and it expects collections to be exposed as IList or ISet.

    I said the same in your other question, but this is something I'm actively working on improving. It's not much consolidation now though, I realise.

    Again, your options are either to live with the compromise in your domain (expose IList), override every occurrence, or not use automapping for these classes.

  2. 3 Posted by Martin on 12 Mar, 2010 02:03 PM

    Martin's Avatar

    Thanks for the answer James
    Looking forward to the next release.

    ... and thanks for all the effort you put into this project. :)

  3. James Gregory closed this discussion on 24 Mar, 2010 09:00 AM.

Comments are currently closed for this discussion. You can start a new one.