title: AutoMapper: How to map only matching property names and ignore all others?
body: <p>I am new to AutoMapper and using version 6.2.2.  I am trying to map a view model to an entity (also using Entity Framework).  I want to update only the properties that exist in both the viewmodel and the entity. The entity has other navigational properties and related objects that are not part of the source viewmodel.  I am currently getting an error that I have unmapped properties on the destination entity.  Both my viewmodel and entity have over 40 properties so I do not want to explicitly add each one to the map.</p>
  
  <p>Here is my code:</p>
  
  <p>Map:</p>
  
  <pre><code>public static void RegisterMaps()
  {
      AutoMapper.Mapper.Initialize(config =&gt;
      {
                      config.CreateMap&lt;EditApplicationViewModel, Application&gt;();
  
      });
  
  }
  </code></pre>
  
  <p>I have also tried the following but get the same error: </p>
  
  <pre><code>config.CreateMap&lt;EditApplicationViewModel, Application&gt;(MemberList.source);
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryToken]
  public ActionResult Edit(EditApplicationViewModel viewModel)
  {
      if (ModelState.IsValid)
      {
          Application application = _applicationService.GetById(viewModel.ApplicationId);
  
          application = Mapper.Map(viewModel, application);
      }
  }
  </code></pre>
  
  <p>Error Message:</p>
  
  <blockquote>
    <p>InnerException: 
           HResult=-2146233088
           Message= Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom
    resolver, or modify the source/destination type For no matching
    constructor, add a no-arg ctor, add optional arguments, or map all of
    the constructor parameters
    ========================================================== String -> User (Destination member list) System.String ->
    <strong><em>.</em></strong>.***.entities.User (Destination member list)</p>
    
    <p>Unmapped properties: <strong><em>removed - a very long list of related objects
    and properties on the destination</em></strong></p>
  
  <pre><code>   Source=AutoMapper
     StackTrace:
          at lambda_method(Closure , EditApplicationViewModel , Application , ResolutionContext )
  </code></pre>
  </blockquote>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I have also tried the following map.  I am not receiving any errors but none of the source properties are updated on the destination.</p>
  
  <pre><code>config.CreateMap&lt;EditApplicationViewModel, Application&gt;().ForAllOtherMembers(opts=&gt;opts.Ignore());
  </code></pre>