title: C# Automapper Ignore Property When Null
body: <p>I am creating an Automapper mapping between my <code>AccountEditViewModel</code> (View Model used for editing a user) and my <code>User</code> (Data Model representing a User in the database). If the password field is filled in, I want to encrypt that password and store it however if it is null in the I want to keep the old password. I have tried the code below however it is wrong, model.Ignore() doesn't return a string value. What is the best way of going about this. Can I accomplish this using the <code>ForMember()</code> method or do I need a custom resolver?</p>
  
  <pre><code>Mapper.CreateMap&lt;AccountEditViewModel, User&gt;()
                  .ForMember(model =&gt; model.Password, model =&gt; model.MapFrom(user =&gt; user.Password != null ? EncryptPassword(user.Password) : model.Ignore()));
  </code></pre>