title: extending PrimaryKey of IdentityUserRole in Identity 2
body: <p>
  Is it possible to extend primary key of ApplicationUserRole by additional column?</p>
  
  <p>by default there are two columns defined as primary key: <code>UserId</code> and <code>RoleId</code></p>
  
  <p>here is default implementation</p>
  
  <pre><code>public partial class ApplicationUserRole : IdentityUserRole&lt;string&gt;
  {
      public virtual ApplicationUser User { get; set; }
      public virtual ApplicationRole Role { get; set; }
  }
  
  public class IdentityUserRole&lt;TKey&gt;
  {
      public IdentityUserRole();
  
      // Summary:
      //     RoleId for the role
      public virtual TKey RoleId { get; set; }
      //
      // Summary:
      //     UserId for the user that is in the role
      public virtual TKey UserId { get; set; }
  }
  </code></pre>
  
  <p>and the table in a db looks like
  </p>
  
  <pre><code>CREATE TABLE [dbo].[AspNetUserRoles](
      [UserId] [nvarchar](128) NOT NULL,
      [RoleId] [nvarchar](128) NOT NULL,
   CONSTRAINT [PK_dbo.AspNetUserRoles] PRIMARY KEY CLUSTERED 
  (
      [UserId] ASC,
      [RoleId] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  </code></pre>
  
  <p>but i need more! :)
  i mean i want my model looks like</p>
  
  <pre><code>public partial class ApplicationUserRole : IdentityUserRole&lt;string&gt;
  {
  
      public Guid ServiceId { get; set; }
  
      public virtual ApplicationUser User { get; set; }
      public virtual ApplicationRole Role { get; set; }
      public virtual Service Service { get; set; }
  
  }
  </code></pre>
  
  <p>I can't understand how to do it in a correct way with data annotations or fluent api. I've tried both without any succes.
  It seems migration engine ignores any primary key changes of that model.
  At least when i add annotation or fluent api methods migration engine generates empty migration script.</p>
  
  <p>i just added serviceId property and my table now looks like
  </p>
  
  <pre><code>CREATE TABLE [dbo].[AspNetUserRoles](
      [UserId] [nvarchar](128) NOT NULL,
      [RoleId] [nvarchar](128) NOT NULL,
      [ServiceId] [uniqueidentifier] NOT NULL,
   CONSTRAINT [PK_dbo.AspNetUserRoles] PRIMARY KEY CLUSTERED 
  (
      [UserId] ASC,
      [RoleId] ASC
  )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
  ) ON [PRIMARY]
  </code></pre>
  
  <p>and when i try to apply key changes via annotations or fluent api
  migration script looks like</p>
  
  <pre><code>public partial class rolesmigrate02 : DbMigration
  {
      public override void Up()
      {
      }
  
      public override void Down()
      {
      }
  }
  </code></pre>
  
  <p>fluent api:</p>
  
  <pre><code>modelBuilder.Entity&lt;ApplicationUserRole&gt;().HasKey(hk =&gt; new { hk.UserId, hk.RoleId, hk.ServiceId});
  </code></pre>
  
  <p>annotations</p>
  
  <pre><code>public partial class ApplicationUserRole : IdentityUserRole&lt;string&gt;
  {
      [Key, Column(Order = 0)]
      public override string UserId { get; set; }
      [Key, Column(Order = 1)]
      public override string RoleId { get; set; }
      [Key, Column(Order = 2)]
      public Guid ServiceId { get; set; }
  
      public virtual ApplicationUser User { get; set; }
      public virtual ApplicationRole Role { get; set; }
      public virtual Service Service { get; set; }
  }
  </code></pre>
  
  <p>i can do changes manualy in a db but i doubt<br>
  where is my mistake? why i can't extend this model by code first migration?</p>