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 1061693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:30:41+00:00 2026-05-16T18:30:41+00:00

If I have a nested source and destination like this: public class UserInformationViewModel {

  • 0

If I have a nested source and destination like this:

public class UserInformationViewModel
{
    public string UserName { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Organization { get; set; }
    public string EmailAddress { get; set; }
    public PhysicalAddressViewModel BillingAddress { get; set; }
    public PhysicalAddressViewModel ShippingAddress { get; set; }
}

public class PhysicalAddressViewModel
{
    public string Line1 { get; set; }
    public string Line2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string PostalCode { get; set; }
    public string Country { get; set; }
}

public class UserInformation
{
    public string UserName { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string Organization { get; set; }
    public string EmailAddress { get; set; }
    public PhysicalAddress BillingAddress { get; set; }
    public PhysicalAddress ShippingAddress { get; set; }
}

public class PhysicalAddress
{
    public AddressType Type { get; set; }
    public string Line1 { get; set; }
    public string Line2 { get; set; }
    public string City { get; set; }
    public string State { get; set; }
    public string PostalCode { get; set; }
    public string Country { get; set; }
}

And AddressType is an enum like this:

public enum AddressType
{
    Billing = 1,
    Shipping = 2,
    Default = 3
};

And I have setup Maps like this:

CreateMap<UserInformationViewModel, UserInformation>();

CreateMap<PhysicalAddressViewModel, PhysicalAddress>();

How can I get automapper to populate AddressType with the proper enum based on the property that is being populated. For example, the PhysicalAddress object that is in UserInformation.BillingAddress should be set to AddressType.Billing while the PhysicalAddress object that is in UserInformation.ShippingAddress should be set to AddressType.Shipping.

I’ve tried everything I can think of to make this work, but I haven’t had any luck.

  • 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-16T18:30:41+00:00Added an answer on May 16, 2026 at 6:30 pm

    Not sure if there’s an easier way, but how about doing something like:

        Mapper.CreateMap<UserInformationViewModel, UserInformation>()
            .AfterMap((src,dst)=>dst.BillingAddress.Type = AddressType.Billing)
            .AfterMap((src,dst)=>dst.ShippingAddress.Type = AddressType.Shipping);
    

    You will need to ignore the Type mapping in the PhysicalAddress also

        Mapper.CreateMap<PhysicalAddressViewModel, PhysicalAddress>()
                    .ForMember(dst=>dst.Type, opt=>opt.Ignore());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 522k
  • Answers 522k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You probably want to start by downloading SQL Server Express,… May 16, 2026 at 9:16 pm
  • Editorial Team
    Editorial Team added an answer Found it, Can be done with Adobe Acrobat Professional, not… May 16, 2026 at 9:16 pm
  • Editorial Team
    Editorial Team added an answer Oddly enough, I rebuilt the nodes and that seemed to… May 16, 2026 at 9:16 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

We're having a problem combining 'nested files' and excluding files from source control. We're
I have a nested ListView control and within the ItemTemplate I need to make
I have some nested movieclips in my banner and can't realize how to prevent
I have two nested div s that are supposed to both be 400 pixels
I have a nested TreeView where I bind the doubleclick event on each item
I have a nested Repeater control in the ItemTemplate of another Repeater. I want
The nested ViewModel is set to the MainWindow DataContext: var mainWindow = new MainWindow();
I have nested ajax calls that are not working in ie7. They work fine
I have a page with two frames, and I need to (via javascript) copy
I have a rails application that models a house. house contains rooms and rooms

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.