title: How to configure Automapper 9 to ignore Object-Properties if object is null but map if not null
body: <p>I´ve tried a lot, but I can´t find what I´m really looking for. This is my case: I have an EF-Core entity with navigation-properties and a viewModel:</p>
  
  <pre><code>public class SomeEntity
  {
      public Guid Id { get; set; }
      public virtual NestedObject NestedObject { get; set; }
      public DateTime Created { get; set; }
      public DateTime Modified { get; set; }
  }
  
  public class SomeEntityViewModel
  {
      public Guid Id { get; set; }
      public string NestedObjectStringValue { get; set; }
      public int NestedValueIntValue { get; set; }
  }
  </code></pre>
  
  <p>This is my CreateMap which creates a new NestedObject even if no NestedObject-Property is set (Condition doesn´t seem to apply here):</p>
  
  <pre><code>CreateMap&lt;SomeEntityViewModel, SomeEntity&gt;(MemberList.Source)
          .ForPath(m =&gt; m.NestedObject.StringValue, opt =&gt;
          {
              opt.Condition(s =&gt; s.Destination.NestedObject != null); 
              opt.MapFrom(m =&gt; m.NestedObjectStringValue);
          });
  </code></pre>
  
  <p>This avoids Creating a new NestedObject if Properties are null but if not, the NestedObject Properties are not mapped:</p>
  
  <pre><code>CreateMap&lt;SomeEntityViewModel, SomeEntity&gt;(MemberList.Source)
      .ForMember(m =&gt; m.NestedObject, opt =&gt; opt.AllowNull());
  </code></pre>
  
  <p>Second CreateMap doesn´t Map NestedObject-Properties if they are set, first creates a new NestedObject if the Properties are not set. But both together are not working. Any ideas how to solve this?</p>