Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7640531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:41:35+00:00 2026-05-31T08:41:35+00:00

I have an interesting scenario and the answer isn’t jumping out at me. I’ve

  • 0

I have an interesting scenario and the answer isn’t jumping out at me. I’ve looked for other similar questions but none seem to address this type of issue.

Before you ask, I do not have control over the source class layout.

My source object looks like this:

class Class1
{
   string string1
   string string2
   string string3
   string string4
   string string5
   string string6
}
class Class2
{
   string foo
   string bar
}
class Class3 //The source object!!
{
   Class1 Inner1
   Class2 Inner2
}

And my destination looks like this:

class Destination
{
   string string1
   string string2
   string string3
   string string4
   string string5
   string string6
   string string7
}

In reality, Inner1 is a huge class and almost a perfect match – except for a couple exceptions. I’d like to use Automapper to directly copy everything from Inner1 to Destination using default matching, but also copy Inner2.foo to Destination.string6 and Inner2.bar to Destination.string7.

EDIT: I should add that right now I am mapping Inner1 to Destination and then doing a couple manual property copies outside of Automapper.

Any suggestions are appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T08:41:37+00:00Added an answer on May 31, 2026 at 8:41 am

    Guessing you currently have something like this:

    Mapper.CreateMap<Inner1, Destination>();
    ...
    var inner1 = GetInner1();
    var destination = Mapper.Map<Destination>(inner1);
    // now do manual hydration on destination using inner2 instance...
    

    You might be able to get away with this:

    Mapper.CreateMap<Inner1, Destination>();
    Mapper.CreateMap<Inner2, Destination>()
        .ForMember(d => d.string6, o => o.ResolveUsing(s => s.foo))
        .ForMember(d => d.string7, o => o.ResolveUsing(s => s.bar))
    ;
    ...
    var inner1 = GetInner1();
    var destination = Mapper.Map<Destination>(inner1);
    
    var inner2 = GetInner2();
    Mapper.Map(inner2, destination);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have an interesting scenario I need to sort out: 1) We have an
I have an interesting scenario. I have a task model which has a task
I'm using SQL Server 2008. I have an interesting scenario where a stored procedure
I have the following interesting scenario: I've install ruby 1.9.2 via RVM and it
I have an interesting dilemma to which, I hope, someone may have an answer.
I have very interesting scenario: I've specified two controllers, one for global events and
I have a interesting scenario that. public class Base { public void hello(){ this.say();
I have the following interesting scenario: The test system, in my case BogusGateway of
I have an interesting scenario and need to know if it can even be
I just came across an interesting scenario. I have a class in C#: public

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.