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

  • Home
  • SEARCH
  • 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 8421631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:12:05+00:00 2026-06-10T03:12:05+00:00

In my data layer I have a repository that can return a list of

  • 0

In my data layer I have a repository that can return a list of items like this:

new List<Item> {
    new Item { Title = "Something", DetailId = 500 },
    new Item { Title = "Whatever", DetailId = 501 },
}

The repository has another method that can return details for these items when given the items detail ID:

// repository.GetDetail(500) would return something like:
new ItemDetail {
    Id = 500,
    Size = "Large"        
}

Now, in my service layer I would like to map a the above list into something like this:

new List<ServiceItem> {
    new ServiceItem { Title = "Something", Size = "Large" },
    new ServiceItem { Title = "Whatever", Size = "Medium" },
}

Note that I need properties both from the objects in the list (Title in this case) and from the detailed objects. Is there any good way to map this with AutoMapper?

I have thought about making a profile that depends on an instance of my repository, and then have AutoMapper do the detail requests, but it sort of feels messy to have AutoMapper fetch new data?

Is there a clean way to map from two objects into one?

  • 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-06-10T03:12:06+00:00Added an answer on June 10, 2026 at 3:12 am

    One possibility would be to wrap your Item and ItemDetail objects in a Tuple and define your Map based off that Tuple. The mapping code would look something like this.

    Mapper.CreateMap<Tuple<Item, ItemDetail>, ServiceItem>()
        .ForMember(d => d.Title, opt => opt.MapFrom(s => s.Item1.Title))
        .ForMember(d => d.Size, opt => opt.MapFrom(s => s.Item2.Size));
    

    You would have to join the correct Item and ItemDetail yourself. If you wanted Automapper to also match the Item to the correct ItemDetail, you would need to change the mapping so that during the resolution of Size, Automapper performs a lookup and returns the Size of the match. The code would look something like this.

    Mapper.CreateMap<Item, ServiceItem>()
        .ForMember(d => d.Size, opt => opt.MapFrom(s => itemDetails.Where(x => s.DetailId == x.Id).First().Size));
    

    This map uses the automapping functionality of Automapper to map Item.Title to ServiceItem.Title. The map is using an IEnumerable named itemDetails to find the match, but it should be possible to replace it with a database call. Now since doing this type of lookup is something that I don’t think Autmapper was designed to do, performance may not be that great for a large number of items. That would be something to test.

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

Sidebar

Related Questions

My application I have an application design that looks like this: web application layer
I have a repository layer that is responsible for my data-access, which is called
We have made a repository layer for interacting with Core Data that have methods
I have a project called Data which is a data layer. In this project,
I have an existing web app that has a data layer and a bll
I have a data access layer (DAL) that is written in ASP.NET 3.5 and
I have created a Data Access Layer using .NET. Everywhere that I update a
As we all know most apps have a data access layer, often using repository
I have a repository data access pattern like so: IRepository<T> { .. query members
I'm working on a project in which we have a database, data layer (entity

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.