title: Foreign Key To Microsoft.AspNet.Identity.EntityFramework.IdentityUser?
body: <p>I'm in VS 2013 and have just created an MVC application.</p>
  
  <p>I'm creating an object I intend to have a foreign key to the AspNetUsers table in the resulting database. The project does have an ApplicationUser (deriving from IdentityUser) that looks like a property-column match with the AspNetUsers table.</p>
  
  <p>How do we properly declare a foreign key to this?</p>
  
  <pre><code>public MyObject
  {
     public string UserId { get; set; }
  
     [ForeignKey("UserId")]
     public ApplicationUser User { get; set;}
  
     // other properties
  }
  </code></pre>
  
  <p>Now, I modify ApplicationUser to have a collection of MyObjects:</p>
  
  <pre><code>public ApplicationUser : IdentityUser
  {
       public virtual ICollection&lt;MyObject&gt; MyObjects { get; set; }    
  }
  </code></pre>
  
  <p>This seems to be how to do one-to-many in EF Code First. However, when I update-database, I'm getting the errors that say Identity members (IdentityUserLogin, IdentityUserRole, etc.) have no keys defined. Perhaps those classes were not meant to participate in EF Code First Migrations?</p>
  
  <p>I could go "to the back" and add the foreign key via SQL statements, but if I wanted to update again from Code First, I might get errors (that the database doesn't currently match the older migration or something like that).</p>
  
  <p>How do we properly foreign-key reference those membership tables?</p>
  
  <p>I also tried to create an AspNetUser class with matching properties of the AspNetUsers table. Instead of "public ApplicationUser" on the Client class, I declared "public AspNetUser". Doing this resulted in a migration failure - "Automatic migration was not applied because it would result in data loss."</p>
  
  <p>So, what to do?</p>