title: AutoMapper - Custom Mappings
body: <p>I am having troubles setting up a custom mapping from my DB entity to my view model using AutoMapper.</p>
  
  <p>My goal is to map the <strong>ApplicationUser</strong> to my <strong>ApplicationUserViewModel</strong>.</p>
  
  <p>I am returning the list of users like this:</p>
  
  <pre><code>return View(Mapper.Map&lt;IEnumerable&lt;ApplicationUserViewModel&gt;&gt;(_userRepository.GetAllUsersWithRoles()));
  </code></pre>
  
  <p>In the Startup.cs my AutoMapper configuration includes the below:</p>
  
  <pre><code>Mapper.Initialize(config =&gt;
  {
     ...
     config.CreateMap&lt;ApplicationUserViewModel, ApplicationUser&gt;().ReverseMap();
  });
  </code></pre>
  
  <p>And I basically want to tell AutoMapper to automatically set the below property of my ViewModel class (IsConnectedToFacebook) to true if the ApplicationUser entity from the DB has a Login stored against it with the provider facebook. So somethink like this:</p>
  
  <pre><code>viewmodel.IsConnectedToFacebook = user.Logins.Any(login =&gt; login.LoginProvider == "Facebook");
  </code></pre>
  
  <p>Here the view model:</p>
  
  <pre><code>public class ApplicationUserViewModel
  {
     ...
     public bool IsConnectedToFacebook { get; set; }
  }
  </code></pre>
  
  <p>Thank you very much for your help!</p>
  
  <p>Nik</p>