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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:46:58+00:00 2026-06-18T10:46:58+00:00

Suppose i have a source class: public class Source { //Several properties that can

  • 0

Suppose i have a source class:

public class Source
{
    //Several properties that can be mapped to DerivedBase and its subclasses
}

And some destination classes:

public class DestinationBase
{
     //Several properties
}

public class DestinationDerived1 : DestinationBase
{
     //Several properties
}

public class DestinationDerived2 : DestinationBase
{
     //Several properties
}

Then I wish the derived destination classes to inherit the automapper configuration of the baseclass because I do not want to have to repeat it, is there any way to achieve this?

Mapper.CreateMap<Source, DestinationBase>()
    .ForMember(...)
    // Many more specific configurations that should not have to be repeated for the derived classes
    .ForMember(...);

Mapper.CreateMap<Source, DestinationDerived1 >()
    .ForMember(...);
Mapper.CreateMap<Source, DestinationDerived2 >()
    .ForMember(...);

When I write it like this it does not use the base mappings at all, and include doesn’t seem to help me.

Edit:
This is what I get:

public class Source
{
    public string Test { get; set; }
    public string Test2 { get; set; }
}

public class DestinationBase
{
    public string Test3 { get; set; }
}

public class DestinationDerived1 : DestinationBase
{
    public string Test4 { get; set; }
}

public class DestinationDerived2 : DestinationBase
{
    public string Test5 { get; set; }
}

Mapper.CreateMap<Source, DestinationBase>()
              .ForMember(d => d.Test3, e => e.MapFrom(s => s.Test))
              .Include<Source, DestinationDerived1>()
              .Include<Source, DestinationDerived2>();

        Mapper.CreateMap<Source, DestinationDerived1>()
              .ForMember(d => d.Test4, e => e.MapFrom(s => s.Test2));

        Mapper.CreateMap<Source, DestinationDerived2>()
              .ForMember(d => d.Test5, e => e.MapFrom(s => s.Test2));

AutoMapper.AutoMapperConfigurationException :
Unmapped members were found. Review the types and members below.

Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type

Source -> DestinationDerived1 (Destination member list)

Test3

  • 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-18T10:46:59+00:00Added an answer on June 18, 2026 at 10:46 am

    Include derived mappings into base mapping:

    Mapper.CreateMap<Source, DestinationBase>()
        .ForMember(d => d.Id, op => op.MapFrom(s => s.Id)) // you can remove this
        .Include<Source, DestinationDerived1>()
        .Include<Source, DestinationDerived2>();
    
    Mapper.CreateMap<Source, DestinationDerived1>()
        .ForMember(d => d.Name, op => op.MapFrom(s => s.Text))
        .ForMember(d => d.Value2, op => op.MapFrom(s => s.Amount));
    
    Mapper.CreateMap<Source, DestinationDerived2>()
        .ForMember(d => d.Value, op => op.MapFrom(s => s.Amount));
    

    Usage:

    Mapper.AssertConfigurationIsValid();
    var s = new Source() { Id = 2, Amount = 10M, Text = "foo" };
    var d1 = Mapper.Map<DestinationDerived1>(s);
    var d2 = Mapper.Map<DestinationDerived2>(s);
    

    See Mapping inheritance on AutoMapper wiki.


    UPDATE: Here is full code of classes which works as it should.

    public class Source
    {
        public int Id { get; set; }
        public string Text { get; set; }
        public decimal Amount { get; set; }
    }
    
    public class DestinationBase
    {
        public int Id { get; set; }
    }
    
    public class DestinationDerived1 : DestinationBase
    {
        public string Name { get; set; }
        public decimal Value2 { get; set; }
    }
    
    public class DestinationDerived2 : DestinationBase
    {
        public decimal Value { get; set; }
    }
    

    UPDATE (workaround of AutoMapper bug):

    public static class Extensions
    {
        public static IMappingExpression<Source, TDestination> MapBase<TDestination>(
            this IMappingExpression<Source, TDestination> mapping)
            where TDestination: DestinationBase
        {
            // all base class mappings goes here
            return mapping.ForMember(d => d.Test3, e => e.MapFrom(s => s.Test));
        }
    }
    

    And all mappings:

        Mapper.CreateMap<Source, DestinationBase>()
              .Include<Source, DestinationDerived1>()
              .Include<Source, DestinationDerived2>()
              .MapBase();
    
        Mapper.CreateMap<Source, DestinationDerived1>()
              .MapBase()
              .ForMember(d => d.Test4, e => e.MapFrom(s => s.Test2));
    
        Mapper.CreateMap<Source, DestinationDerived2>()
              .MapBase()
              .ForMember(d => d.Test5, e => e.MapFrom(s => s.Test2));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a destination class and a source class that are mostly the
Suppose I have a source file open and I launch a shell. I can
Suppose I have a source file that is 18218 bytes. I open the file
Suppose I have two lists that holds the list of source file names and
suppose that,we have following code auto_ptr<T> source() { return auto_ptr<T>( new T(1) ); }
Suppose we have this problem public class Father{ public void method1(){...} } public class
Let's suppose I have this object: [Serializable] public class MyClass { public int Age
Suppose I have a MessageBox class along the following lines: class MyMessageBox { public:
Suppose, I have a simple type: public class Report { public Report() { BirthDate
Suppose you have a Java class which defines a copyFile(String, String) method: public class

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.