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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:08:01+00:00 2026-05-30T01:08:01+00:00

I have a Customers EF POCO class which contains a reference to the Address

  • 0

I have a Customers EF POCO class which contains a reference to the Address table.

The following code seems to work, but I’m not sure it’s the cleanest way to do this. Is there a better way to map this using only a single Map call?

    [HttpGet]
    public ActionResult Details(string ID)
    {
        BusinessLogic.Customers blCustomers = new BusinessLogic.Customers("CSU");
        DataModels.Customer customer = blCustomers.GetCustomer(ID);

        CustomerDetailsViewModel model = new CustomerDetailsViewModel();

        Mapper.CreateMap<DataModels.Customer, CustomerDetailsViewModel>();
        Mapper.CreateMap<DataModels.Address, CustomerDetailsViewModel>();
        Mapper.Map(customer, model);
        Mapper.Map(customer.Address, model);

        return View(model);
    }
  • 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-30T01:08:03+00:00Added an answer on May 30, 2026 at 1:08 am

    It depends on what your CustomerDetailsViewModel looks like. For example, if your Address class looks something like this:

    public class Address 
    {
        public string Street { get; set; }
        public string City { get; set; }
    }
    

    and CustomerDetailsViewModel contains properties following this convention:

    When you configure a source/destination type pair in AutoMapper, the
    configurator attempts to match properties and methods on the source
    type to properties on the destination type. If for any property on the
    destination type a property, method, or a method prefixed with “Get”
    does not exist on the source type, AutoMapper splits the destination
    member name into individual words (by PascalCase conventions).

    (Source: Flattening)

    Then, if CustomerDetailsViewModel has properties:

    public string AddressStreet { get; set; }
    public string AddressCity { get; set; }
    

    Just one mapping from Customer to CustomerDetailsViewModel will work. For members that don’t match that convention, you could use ForMember.

    You can always use ForMember for every single address property as well:

    Mapper.CreateMap<DataModels.Customer, CustomerDetailsViewModel>()
        .ForMember(dest => dest.Street, opt => opt.MapFrom(src => src.Address.Street));
        /* etc, for other address properties */
    

    Personally, I wouldn’t be too worried about calling .Map twice. At least that way it’s very clear that both Address and Customer properties are being mapped.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following POCO's: [PetaPoco.TableName(Customer)] [PetaPoco.PrimaryKey(ID)] public class User { [Required(ErrorMessage = Please
I have Customers table: Customer(id, name status_id). I have Statuses table: Status(id, name, code).
I have the following Entity Framework POCO classes: public class Customer { public int
I have a Customers table with a foreign reference to the Addresses table. It
I have several customers where my WinForms app does not perform as well as
I have a Customers table and would like to assign a Salesperson to each
Lets say I have a Customers table and an Orders table with a one-to-many
If I have a Customers table linked to an Orders table, and I want
I have 5 tables: customers id - name p_orders id - id_customer - code
i have some customers with a particular address that the user is searching for:

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.