AutoMap component collection

30 views
Skip to first unread message

Jochen Jonckheere

unread,
Oct 5, 2011, 4:07:09 AM10/5/11
to fluent-n...@googlegroups.com
Hi,

I have a few entities that have an Address, in most of the classes they are mapped as component. This done via AutoMapping with:

    public override bool IsComponent(Type type)
    {
        return type == typeof(Address);
    }

But one of my entities now needs a collection of Addresses, AutoMapper doens't pick this up, so I made an override like this:

    public class ConsultantMappingOverride : IAutoMappingOverride<Consultant>
    {
        public void Override(AutoMapping<Consultant> mapping)
        {
            mapping.HasMany(c => c.WorkAddresses)
                .AsBag()
                .Table("`ConsultantWorkAddress`")
                .Component(c =>
                               {
                                   c.Map(a => a.Street);
                                   c.Map(a => a.HouseNumber);
                                   ...
                               });
        }
    }

In fact this seems to work, but now I have my Address automapped as component and I had to do it manually for the HasMany. Is there a better way?

Jochen
Reply all
Reply to author
Forward
0 new messages