title: Automapper - Map nested object with private ctor and private setters only if all fields are not null
body: <h2>Scenario</h2>
  <p>This scenario is a simplified model, notice</p>
  <ul>
  <li>the <em>private</em> parameterless constructors</li>
  <li>the <em>private setter</em> on properties</li>
  </ul>
  <pre><code>class Nested 
  {
      public int Month { get; private set; }
  
      public int Year { get; private set; }
  
      private Nested() { }
  
      public Nested(int month, int year)
      {
           // There are some validations but the simplicity of this example I omitted its
           Month = month; 
           Year = year;
      }
  }
  
  
  class Root
  {
       public int Id { get; private set; }
  
       public string Title { get; private set; }
  
       public Nested Nested { get; private set; }
  
       private Root() { }
  
       public Root(int id, string title, Nested nested)
       {
             // There are some validations but the simplicity of this example I omitted its
             Id = id;
             Title = title;
             Nested = nested;
       }
  }
  </code></pre>
  <p>Now I have a DB flatten class</p>
  <pre><code>class RootDb
  {
      public int Id { get; set; }
  
      public string Title { get; set; }
  
      public int? Nested_Month { get; set; }
  
      public int? Nested_Year { get; set; }
  }
  
  </code></pre>
  <h2>What to achieve</h2>
  <p>I want to Map from RootDb to Root but omit (set to null) the Nested ValueObject property if ALL fields are nulls and DO NOT USE the public Nested constructor.</p>
  <h2>What I try</h2>
  <p>This code doesn't work, the Nested property is set to <code>Nested { Year = null, Month = null }</code></p>
  <pre><code>CreateMap&lt;Root, RootDb&gt;()
       .ForMember(p =&gt; p.Nested_Month, o =&gt; o.MapFrom(f =&gt; f.Mested.Month))
       .ForMember(p =&gt; p.Nested_Year, o =&gt; o.MapFrom(f =&gt; f.Nested.Year))
       .ReverseMap()
       .ForMember(p=&gt; p.Nested, o =&gt; o.Condition(src =&gt; src.Nested_Month != null &amp;&amp; src.Nested_Year != null))
       ;
   
  </code></pre>
  <h2>The working solution</h2>
  <p>I found this solution but is it the only one?
  I think is overcomplicated</p>
  <pre><code>CreateMap&lt;Root, RootDb&gt;()
       .ForMember(p =&gt; p.Nested_Month, o =&gt; o.MapFrom(f =&gt; f.Mested.Month))
       .ForMember(p =&gt; p.Nested_Year, o =&gt; o.MapFrom(f =&gt; f.Nested.Year))
       ;
  
  CreateMap&lt;RootDb, Nested&gt;()
       .ForMember(p =&gt; p.Month, o =&gt; o.MapFrom(f =&gt; f.Nested_Month))
       .ForMember(p =&gt; p.Year, o =&gt; o.MapFrom(f =&gt; f.Nested_Year))
       .ForAllOtherMembers(p=&gt; p.Ignore())
       ;
  
  CreateMap&lt;RootDb, Root&gt;()
       .ForMember(p =&gt; p.Nested, o =&gt;
       {
          o.Condition(src =&gt;
              src.Nested_Month != null &amp;&amp;
              src.Nested_Year != null);
          o.MapFrom(f =&gt; f);
       })
       ; 
  </code></pre>
  <p>Any suggestion ?</p>