title: The entity type 'IdentityUserLogin<string>' requires a primary key to be defined
body: <p>i am using dotnet core 1.1 on linux, and i am having issues when i want to split up the identityContext from my regular dbContext, whenever i run the following line in my startup.cs --> configure:</p>
  
  <pre><code>//... some other services
  using (var serviceScope = app.ApplicationServices.GetRequiredService&lt;IServiceScopeFactory&gt;().CreateScope())
  {
      serviceScope.ServiceProvider.GetService&lt;ApplicationDbContext&gt;().Database.Migrate();
      //running other database.migrations here + seeding data. But it is the line above that causes problems
  </code></pre>
  
  <p>So this line throws the exception: The entity type 'IdentityUserLogin' requires a primary key to be defined</p>
  
  <p>I simply don't understand this, why is it my job to give the IdentityUserLogin a primary key??, it is a 3rd party class and i haven't even touched it. I have the following simple setup:</p>
  
  <pre><code>namespace EsportshubApi.Models
  {
      public class ApplicationDbContext :  IdentityDbContext&lt;ApplicationUser&gt;
      {
          public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options) : base(options)
          {
          }
  
          public ApplicationDbContext()
          {
  
          }
  
          protected override void OnModelCreating(ModelBuilder modelBuilder)
          {
              base.OnModelCreating(modelBuilder);
  
  
          }
      }
  }
  </code></pre>
  
  <p>And the applicationUser:</p>
  
  <pre><code>namespace EsportshubApi.Models.Entities
  {
  
      public class ApplicationUser : IdentityUser
      {
          public ApplicationUser() { }
  
          public static ApplicationUserBuilder Builder()
          {
              return new ApplicationUserBuilder(new ApplicationUser());
          }
  
          public int AccountId { get; set; }
          public Guid AccountGuid { get; set; }
          public string Salt { get; set; }
          public bool Verified { get; set; }
          public string Checksum { get; set; }
          public string Password { get; set; }
          public DateTime Created { get; set; }
          public DateTime Updated { get; set; }
      }
  
  }
  </code></pre>
  
  <p>In my startup i am configuring the identity framework the following way:</p>
  
  <p>configureServices:</p>
  
  <pre><code>services.AddEntityFrameworkSqlServer().AddMySQL().AddDbContext&lt;ApplicationDbContext&gt;(options =&gt;
                      options.UseMySQL(config["ConnectionStrings:DefaultConnection"]));
  </code></pre>
  
  <p>And </p>
  
  <p>Configure:</p>
  
  <pre><code> app.UseIdentity();
  </code></pre>
  
  <p>My project is opensourced at : <a href="https://github.com/DenLilleMand/esportshubapi" rel="noreferrer">my github repo</a></p>
  
  <p>if that helps. </p>
  
  <p>I have tried a lot of things. The two most promising was deriving all of the classes used in this generic show, and passing them in explicitly, tried to change all of their keys to ints etc. And that gave the exact same error just with <code>int</code> instead of string.  The other way i tried was to do the following inside of <code>OnModelCreating</code> to give IdentityUserLogin a primary key by e.g :</p>
  
  <pre><code> modelBuilder.Entity&lt;IdentityUserLogin&lt;int&gt;&gt;()
              .Property(login =&gt; login.UserId)
              .ForMySQLHasColumnType("PK")
              .UseSqlServerIdentityColumn()
              .UseMySQLAutoIncrementColumn("AI");
  </code></pre>
  
  <p>As you can see, this was back when i had UserId as a integer, but i am not even sure if the UserId should be its primaryKey. I can get other errors instead of this one, that says</p>
  
  <blockquote>
    <p>IdentityUserLogin is part of a hierarchy, and it has no discriminator values</p>
  </blockquote>
  
  <p>But if I had discriminator values it eventually just goes back to this error. The weirdest part i think is that i have the EXACT same implementation as the UnicornStore github example, that uses a bit of the identity framework as well .... So i really need your help guys. Can reproduce this error by downloading the project, copying the <code>default.appsettings.json</code> into <code>appsettings.json</code>, put in a valid connectionstring, <code>dotnet restore</code>, run with <code>dotnet run --environment Development</code>.</p>
  
  <p>I even tried to change out the implementation to use a MSSQL database instead of MySQL, but that gave the exact same error. </p>