AutoMapper - Map two source collections of different types into a single destination collection
<p>I have two collections on a source object of different types. I want to map both collections (a union of the two) to a single destination collection of a type that has all the members from both the source types. If I do this:</p>

<pre><code>CreateMap&lt;Company, CompanyResponse&gt;()
                .ForMember(x =&gt; x.Owners, m =&gt; m.MapFrom(x =&gt; x.BusinessOwners))
                .ForMember(x =&gt; x.Owners, m =&gt; m.MapFrom(x =&gt; x.IndividualOwners));
</code></pre>

<p>It only maps the last mapping. I tried a more elaborate mapping but this appeared to break the entity framework projection integrations that automapper does. I am using ProjectTo.</p>

<p>This is what I tried which also does a good job of conveying the result I want.</p>

<pre><code>    CreateMap&lt;Company, CompanyResponse&gt;()
        .ForMember(x =&gt; x.Owners, m =&gt; m.ResolveUsing(x =&gt; x.BusinessOwners.Select(o =&gt; new OwnerResponse
         {
             Type = UpdateRegistrationCommand.CompanyUpdate.OwnerType.Business,
             Address = o.Address,
             PercentageShareholding = o.Percentage,
             BusinessName = o.Name,
             BusinessNumber = o.Number
         })
        .Union(x.IndividualOwners.Select(o =&gt; new OwnerResponse
        {
            Type = UpdateRegistrationCommand.CompanyUpdate.OwnerType.Individual,
            Address = o.Address,
            PercentageShareholding = o.Percentage,
            Title = o.Title,
            FirstName = o.FirstName,
            MiddleNames = o.MiddleNames,
            LastName = o.LastName
        }))));
</code></pre>

<p>Has anyone done something like this?</p>