Automapping encapsulated collection

Asger Hallas's Avatar

Asger Hallas

07 May, 2010 09:02 AM via web

I think I've searched everywhere, but I've only found old posts on the subject.
Forgive me if this is already answered elsewhere.

Is there a way to automap such a pair:

ISet<Product> products;
public virtual IEnumerable<Product> Products
{
     get { return products; }
}

Such that I will not have to map it manually like this:

 mapping.HasMany(x => x.Log).AsSet().Access.CamelCaseField();

It does not seem to recognize the property as a OneToMany?

Cheers,
Asger Hallas

  1. Support Staff 2 Posted by James Gregory on 16 May, 2010 05:15 PM

    James Gregory's Avatar

    Hi Asger,

    About a day ago I put in some changes for the automapper to make it work with read-only properties (such as your example). There's a new configuration method which allows you to specify how read-only collections should be accessed, by default autoproperties are treated as access="backfield" and setterless properties as access="nosetter.camelcase".

    The only caveat is that your situation might not still function as you want, because we have no way to detect that your backing field is an ISet currently. If the automapper encounters an IEnumerable it defaults to a bag.

  2. 3 Posted by Asger Hallas on 18 May, 2010 07:35 AM

    Asger Hallas's Avatar

    Hi James
    That looks very good. I've been toying around with it now and can pretty much make it fit my conventions. Except for that ISet thing you mention. I wonder though, if that could be addressed by mapping the private field directly instead - I think I saw a recently resolved issue covering that :)

    Thank you!

  3. Support Staff 4 Posted by Paul Batum on 18 May, 2010 11:51 AM

    Paul Batum's Avatar

    I agree that its worth investigating the possibility of having the
    automapper map the field rather than the public getter. It could be a while
    before we resolve the issue of conventions not being able to change between
    collection types.

  4. 5 Posted by mynkow on 13 Jul, 2010 06:53 AM

    mynkow's Avatar

    Is there a solution for this?

Reply to this discussion

Preview Comments are parsed with Markdown. Help with syntax

Attached Files

    You can attach files up to 10MB

    Ten divided by two is what?