title: Use base class mappings for derived class - Entity Framework 5
body: <p>I want to make a derived class for my User object that has some extra properties (LoginUser class), but entity framework then returns the derived class when I fetch a User from the database. This is unwanted.. The derived class has no parameter-less constructor and should only be created as a wrapper for the login.. So I added to this to the onCreateModel:"</p>
  
  <pre><code>modelBuilder.Ignore&lt;LoginUser &gt;();
  </code></pre>
  
  <p>But now when I try to store or reference my LoginUser object it throws an exception saying the entity has no mapping (LoginUser). How can I make entity framework use the mappings for the base class?</p>
  
  <p>This are my classes:</p>
  
  <pre><code>public class User
  {
      public int Id { get; set; }
  
      public string Name { get; set; }
  
      public string Role { get; set; }
  }
  
  
  
  public class LoginUser : User, IPrincipal
  {
      private IPrincipal underlayingPrincipal;
  
      public IIdentity Identity 
      {
          get
          {
              return this.underlayingPrincipal.Identity;
          }
      }
  
      public LoginUser(IPrincipal principal, User user)
      {
          this.underlayingPrincipal = principal;
          this.Id = user.Id;
          this.Name = user.Name;
          this.Role = user.Role;
      }
  
      public bool IsInRole(string role)
      {
          return this.Role == role;
      }
  }
  </code></pre>