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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:48:56+00:00 2026-06-13T17:48:56+00:00

I want to map the class (Entity), public class Source { public int x;

  • 0

I want to map the class (Entity),

public class Source {
   public int x;
   public string y;
   public bool z;

   public int a;
   public int b;
   public int c;

   //bunch of other fields
   //...
   //..
   //.
}

to the following class (View Model):

public class Destination {
   public MyClass1 A;
   public MyClass2 B;
}

where MyClass1, MyClass2 are defined as follows:

public class MyClass1 {
   public int x;
   public string y;
   public bool z;
}

public class MyClass2 {
   public int a;
   public int b;
   public int c;
}

Is this possible with Automapper?

  • 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-13T17:48:58+00:00Added an answer on June 13, 2026 at 5:48 pm

    Just tested this, and it works in isolation…

            Mapper.CreateMap<Source, MyClass1>();
            Mapper.CreateMap<Source, MyClass2>();
    
            Mapper.CreateMap<Source, Destination>()
                .ForMember(x => x.A, m => m.MapFrom(p => p))
                .ForMember(x => x.B, m => m.MapFrom(p => p));
    
    
            var source = new Source() { a = 1, b = 2, c = 3, x = 4, y = "test", z = true };
            var destination = new Destination() { A = new MyClass1(), B = new MyClass2() };
            Mapper.Map<Source, Destination>(source, destination);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to map from entity to model Entity: public class FileEntity { public
my application has the following entity: public class User { public virtual int UserID
I have entity like below public abstract class MyBaseClass { public int Id {
I have a DB entity like:- public class DBThing { public int Id {
I want to do something like this: @Entity public class Bar { @Id @GeneratedValue
public class User { public int Id {get;set;} public string Name {get;set} public ICollection<User>
I have a standard Domain Layer entity: public class Product { public int Id
I have a base class called Entity: public class Entity { public int Id
Please consider following sample @Entity public class Abc { @Id private Long id; @Unindexed
I have the following Dto and entity with a nested sub entity. 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.