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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:17:22+00:00 2026-05-27T12:17:22+00:00

Consider these 3 simplified example types I pass up and down (I actually only

  • 0

Consider these 3 simplified example types I pass up and down (I actually only automap between DomainObject and WrapperClass though):

public class DomainObject
{
   public int Prop1 {get;set;}
   public int Prop2 {get;set;}
   public int ComputedValue1 {get;set;}
   public int ComputedValue2 {get;set;}
}

public class DALEntity
{
   public int Prop1 {get;set;}
   public int Prop2 {get;set;}
}

public class Wrapper
{
   public DALEntity ToFromDB {get;set;}
   public int ComputedValue1 {get;set;}
   public int ComputedValue2 {get;set;}
}

The DomainObject is what most of my application deals with, while DALEntity is what my data access layer deals with when CUDing around with the DB. Notice there are (in this case) 2 computed values that do not get persisted – rather they are computed externally (for this example doesnt matter how). Hence I would rather not include them in my DALEntity.

For mapping upward (src==DALEntity, dest==DomainObject), Id like to tell Automapper that for any field in DomainObject it doesnt know how to populate, “look in this complex property for a property where the name matches”. As I understand it, right now, I need to explicitly specify all the properties manually via MapFrom when I create the mapping. Would be a real timesaver (and less error prone) to be able to specify a kind of “using” statement for how to map.

I guess you could call it “Projection via hint” 🙂

Is this currently possible?

  • 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-27T12:17:23+00:00Added an answer on May 27, 2026 at 12:17 pm

    I would move the computation of the computed properties to its own class. You could then use dependency injection and have the computed properties call the injected class to populate themselves. AutoMapper shouldn’t have to know this. The DO should be aware of what it needs to be fully operational, or, barring that, its factory should.

    This also would increase the testability of the class.

    Anyways, if you still want to go this route you can pass in a function to the mapping method of Automapper.

    Something like:

     Mapper.CreateMap<DAL, DO>()
                    .ForMember(m => m.CalcProp, 
                               opt => opt.MapFrom(src => 
                                { anon function that calls calculating code, passing src } ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

consider the following simplified example: public class Ticket { public int Id; public TicketState
Consider these classes. class Base { ... }; class Derived : public Base {
consider the following example: public IEnumerable<String> Test () { IEnumerable<String> lexicalStrings = new List<String>
Let's consider the following simplified Resource hierarchy: public abstract class Resource { static public
Consider these two structures: struct Task { public Int32 Id; public String Name; public
Consider the (highly simplified) following case: class Dispatcher { public: receive() {/*implementation*/}; // callback
Consider the following simplified example and desired output: class A { class combined_iterator {
Consider these two functions: Function A takes inputStream as parameter. public void processStream(InputStream stream)
Consider these 2 examples... $key = 'jim'; // example 1 if (isset($array[$key])) { //
Consider these types: struct A {}; struct B : A { int i; };

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.