title: ASP.NET Core Web API - How to add custom ApiAuthorizationDbContext
body: <p>In ASP.NET Core-6 Web API, I am trying to implement IdentityDBContext using ApiAuthorizationDbContext. I want to customize the Primary Key from string to long.</p>
  <p>I have these models:</p>
  <pre><code>public class ApplicationUser : IdentityUser&lt;long&gt;
  {
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string MobileNumber { get; set; }
  
      [DefaultValue(false)]
      public bool? IsAdmin { get; set; }
      public ICollection&lt;ApplicationUserRole&gt; UserRoles { get; set; }
  }
  
  public class ApplicationRole : IdentityRole&lt;long&gt;
  {
      public ICollection&lt;ApplicationUserRole&gt; UserRoles { get; set; }
  }
  
  public class ApplicationUserRole : IdentityUserRole&lt;long&gt;
  {
      public virtual ApplicationUser User { get; set; }
      public virtual ApplicationRole Role { get; set; }
  }
  </code></pre>
  <p>I separated the context for both Identity and the application DB Contexts:</p>
  <p>For the Identity I have:</p>
  <pre><code>public class ApplicationIdentityDbContext : ApiAuthorizationDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationIdentityDbContext(DbContextOptions&lt;ApplicationIdentityDbContext&gt; options,
          IOptions&lt;OperationalStoreOptions&gt; operationalStoreOptions) : base(options, operationalStoreOptions)
      {
      }
  }
  </code></pre>
  <p>Then for the application, I have:</p>
  <p>Then in the ApplicationDbContext, I have this:</p>
  <pre><code>public interface IApplicationDbContext
  {
      public DbSet&lt;RefreshToken&gt; RefreshTokens { get; set; }
  }
  </code></pre>
  <p>I customized the Identity keys from string to long.</p>
  <pre><code>public class ApplicationDbContext : ApiAuthorizationDbContext&lt;ApplicationUser, ApplicationRole, long, ApplicationUserRole&gt;, IApplicationDbContext
  {
      public DbSet&lt;RefreshToken&gt; RefreshTokens { get; set; }
  
      public ApplicationDbContext(DbContextOptions&lt;DDMDbContext&gt; options)
          : base(options)
      {
      }
  }
  </code></pre>
  <p>I got this error in the ApplicationIdentityDbContext:</p>
  <blockquote>
  <p>Severity  Code    Description Project File    Line    Suppression State
  Error   CS0305  Using the generic type 'ApiAuthorizationDbContext' requires 1 type arguments</p>
  </blockquote>
  <p>So, I followed this post:</p>
  <p><a href="https://stackoverflow.com/questions/58208894/asp-net-core-identity-custom-apiauthorizationdbcontext">ASP .NET Core Identity custom ApiAuthorizationDbContext</a></p>
  <p>But I find it difficult to customize or edit anything in</p>
  <blockquote>
  <p>public class ApiAuthorizationDbContext : IdentityDbContext, IPersistedGrantDbContext, IDisposable where TUser : IdentityUser</p>
  </blockquote>
  <p>as instructed in the post above.</p>
  <p>How do I achieve this or where do I get the original path of ApiAuthorizationDbContext?</p>
  <p>Thank you.</p>