Automapping encapsulated collection
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
Support Staff 2 Posted by James Gregory on 16 May, 2010 05:15 PM
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 asaccess="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 anIEnumerable
it defaults to a bag.3 Posted by Asger Hallas on 18 May, 2010 07:35 AM
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!
Support Staff 4 Posted by Paul Batum on 18 May, 2010 11:51 AM
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.
5 Posted by mynkow on 13 Jul, 2010 06:53 AM
Is there a solution for this?