title: Extending IdentityUser with EF Code-first on VS 2013 SPA AccountController
body: <p>Me and a classmate are working on a Phonegap application using a Web API as our backend. Previously we had a working prototype using the old membership function on a MVC4 template.</p>
  
  <p>We've found some pretty good tutorials on how to extend the IdentityUser on a normal mvc controller. We managed to get that to work but going over to the API accountcontroller that comes with the VS 2013 SPA template, we've not managed to get it to work. To simplify our problem here is basicly what we want to do.</p>
  
  <p>Lets say we have a Movie class like this:</p>
  
  <pre><code>public class Movie
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public virtual ApplicationUser User { get; set; }
  }
  </code></pre>
  
  <p>I've created the ApplicationUser like this(taken from the VS 2013 MVC template with individual account):</p>
  
  <pre><code>public class ApplicationUser : IdentityUser
  {
      public string DisplayName { get; set; }
  }
  
  public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext()
          : base("DefaultConnection")
      {
      }
  
      public DbSet&lt;Movie&gt; Films { get; set; }
  }
  </code></pre>
  
  <p>I have added this line in Application_Start on global.asax:</p>
  
  <pre><code>Database.SetInitializer&lt;ApplicationDbContext&gt;(new AppDbInit());
  </code></pre>
  
  <p>The AppDbInit class:</p>
  
  <pre><code>public class AppDbInit : DropCreateDatabaseAlways&lt;ApplicationDbContext&gt;
  {
  
  }
  </code></pre>
  
  <p>I changed the UserManagerFactory in Startup.Auth.cs:</p>
  
  <pre><code>UserManagerFactory = () =&gt; new UserManager&lt;ApplicationUser&gt;(new UserStore&lt;ApplicationUser&gt;());
  
  public static Func&lt;UserManager&lt;ApplicationUser&gt;&gt; UserManagerFactory { get; set; }
  </code></pre>
  
  <p>In the AccountController.cs file I've replaced all occurrences of IdentityUser with ApplicationUser instead. Once that was done, I started to get errors by class files inside Microsoft.AspNet.Identity.EntityFramework that are using the IdentityUser class saying it cannot convert IdentityUser to ApplicationUser.
  One of such entityframework classes is:</p>
  
  <pre><code>namespace Microsoft.AspNet.Identity.EntityFramework
  {
  public class IdentityUserLogin
  {
      public IdentityUserLogin();
  
      public virtual string LoginProvider { get; set; }
      public virtual string ProviderKey { get; set; }
      public virtual IdentityUser User { get; set; }
      public virtual string UserId { get; set; }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I created my own class ApplicationUserLogin where I changed the User property to one of type ApplicationUser, that did not work either.</p>
  
  <p>This is where I'm stuck. I e-mailed and asked for help and was suggested to write my own UserStore class implementing the IUserStore interface. Is that the only way to extend the EF code-first database that asp.net Identity creates or am I close? I could perhaps just keep my user accounts in one database and the rest in another but I would prefer to get this to work.</p>
  
  <p>Oh and this is the article I've been using mainly (which like I said I managed to get workin on a standard mvc controller):
  <a href="http://blogs.msdn.com/b/webdev/archive/2013/10/20/building-a-simple-todo-application-with-asp-net-identity-and-associating-users-with-todoes.aspx" rel="noreferrer">http://blogs.msdn.com/b/webdev/archive/2013/10/20/building-a-simple-todo-application-with-asp-net-identity-and-associating-users-with-todoes.aspx</a></p>