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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:33:28+00:00 2026-06-11T07:33:28+00:00

I would like to setup an Automapper mapping that follows the following rules. If

  • 0

I would like to setup an Automapper mapping that follows the following rules.

  • If the “in place” destination syntax is not used, map a particular member to a value
  • If an object is passed in, then use the destination value

I’ve tried this every way I can think of. Something like this:

Mapper.CreateMap<A, B>()
    .ForMember(dest => dest.RowCreatedDateTime, opt => {
        opt.Condition(dest => dest.DestinationValue == null);
        opt.UseValue(DateTime.Now);
     });

This always maps the value. Essentially what I want is this:

c = Mapper.Map<A, B>(a, b);  // does not overwrite the existing b.RowCreatedDateTime
c = Mapper.Map<B>(a);        // uses DateTime.Now for c.RowCreatedDateTime

Note: A does not contain a RowCreatedDateTime.

What are my options here? It’s very frustrating since there appears to be no documentation on the Condition method, and all the google results seem to be focused around where the source value is null, rather than the destination.

EDIT:

Thanks to Patrick, he got me on the right track..

I figured out a solution. If anyone has a better way of doing this, please let me know. Note I had to reference dest.Parent.DestinationValue rather than dest.DestinationValue. For some reason, dest.DestinationValue is always null.

.ForMember(d => d.RowCreatedDateTime, o => o.Condition(d => dest.Parent.DestinationValue != null))
.ForMember(d => d.RowCreatedDateTime, o => o.UseValue(DateTime.Now))
  • 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-11T07:33:30+00:00Added an answer on June 11, 2026 at 7:33 am

    I believe you need to set up two mappings: one with the Condition (which determines IF a mapping should be performed) and one which defines what to do if the Condition returns true. Something like this:

    .ForMember(d => d.RowCreatedDateTime, o => o.Condition(d => d.DestinationValue == null);
    .ForMember(d => d.RowCreatedDateTime, o => o.UseValue(DateTime.Now));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to setup my gallery web page so that when a user
I would like to setup Feedback link on every windows form, so that user
I have 2 models that I would like to setup routes for: Apps and
I would like to setup a admin page (ASP.NET/C#) that can add IIS host
I would like to setup some automated testing of test cases upon Fortran binaries
I would like to setup TinyMCE to allow literally any HTML without any cleaning
I would like to setup a multi-tenant ASP.NET MVC app. Ideally, this app would
I would like to setup my maven release to run in batch mode, but
I would like to setup a simple loginpage for my webapp. As the app
i would like to setup auto deployment script to my testing server locally. i'm

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.