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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:08:10+00:00 2026-06-03T23:08:10+00:00

I have a question with regards to automapping entity framework objects which have been

  • 0

I have a question with regards to automapping entity framework objects which have been “deep loaded”. I have a Project object which has a member called Tasks which is a collection. And each task has a member called Works which is a collection. When the Project is deep loaded, those Tasks and their Works member are all populated. It looks like this:

-- Project
    -- Task 1
        -- Work 1
        -- Work 2
    -- Task 2
        -- Work 3

I have figured out how to map 1 level deep using a resolver like this:

CreateMap<DataAccess.Task, Entities.Task>()
            .ForMember(obj => obj.Description, obj => obj.MapFrom(src => src.Description))
            .ForMember(obj => obj.Estimate, obj => obj.MapFrom(src => src.Estimate))
            .ForMember(obj => obj.Id, obj => obj.MapFrom(src => src.ID))
            .ForMember(obj => obj.ProjectId, obj => obj.MapFrom(src => src.Project))
            .ForMember(obj => obj.TaskName, obj => obj.MapFrom(src => src.TaskName))
            .ForMember(obj => obj.Visible, obj => obj.MapFrom(src => src.Visible))
            .ForMember(obj => obj.WorkItems, obj => obj.ResolveUsing<WorkItemsResolver>().FromMember(src => src.Works));

public class WorkItemsResolver : ValueResolver<EntityCollection<DataAccess.Work>, ICollection<Entities.Work>>
{
    #region Overrides of ValueResolver<List<Task>,List<Task>>

    protected override ICollection<Entities.Work> ResolveCore(EntityCollection<DataAccess.Work> source)
    {
        Mapper.EntitiesMapper entitiesMapper = new EntitiesMapper(); 
        return source.Select(wk => entitiesMapper.Map<Entities.Work>(wk)).ToList();
    }

    #endregion
}

However, I cannot figure out how to go 2 levels deep i.e. to be able to map a top level object (Project) and have it’s child lists (and their child lists) also get mapped to their concommitant business objects.

Does anyone know if this is possible with Automapper?

Thanks

  • 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-03T23:08:11+00:00Added an answer on June 3, 2026 at 11:08 pm

    You should have a corresponding DataAccess object for each Entity object. You already have a Task mapping, now you need one for Work. Also, don’t use separate ValueResolvers. You can do anything you need using the lambda overloads in ForMember.

    CreateMap<DataAccess.Task, Entities.Task>()
        // when names match on both sides, there is no need to call ForMember
        //.ForMember(obj => obj.Description, obj => obj.MapFrom(src => src.Description))
        //.ForMember(obj => obj.Estimate, obj => obj.MapFrom(src => src.Estimate))
        //.ForMember(obj => obj.Id, obj => obj.MapFrom(src => src.ID))
        .ForMember(obj => obj.ProjectId, obj => obj.MapFrom(src => src.Project))
        //.ForMember(obj => obj.TaskName, obj => obj.MapFrom(src => src.TaskName))
        //.ForMember(obj => obj.Visible, obj => obj.MapFrom(src => src.Visible))
        .ForMember(obj => obj.WorkItems, obj => obj.ResolveUsing(src =>
            Mapper.Map<IEnumerable<DataAccess.Work>>(src.Works)))
    ;
    
    CreateMap<DataAccess.Work, Entities.Work>()
        // only call ForMember on properties that don't map automatically
    ;
    

    Since you created a map for your 2’nd level of depth in the object hierarchy, you can just call Mapper.Map in the ResolveUsing lambda overload.

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

Sidebar

Related Questions

i have this question about Visual Studio 2010 entity framework designer. Is there a
I have got a question with regards to upgrading asp.net mvc applications from v1
I have a general question with regards to immutable collections. I will use Java
I have just asked this question an hour ago but with regards to IE8
I just have a question in regards to threads that run concurrently and the
I just have a little question with regards to connecting C to MySQL. Well,
I have a question. What is wrong with regards to the below code: ArrayList
I have a question with regards Google Code svn repositories. Is there a way
I have a question in regards to the code below. The code I have
I have a question in regards to pressing the cancel button of my inputDialoguebox.

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.