title: Using Custom Entities with OpenIddict
body: <p>I'm trying to extend the entities used by OpenIddict based on the example provided here:
  <a href="https://github.com/openiddict/openiddict-core/issues/360#issuecomment-280268525" rel="nofollow noreferrer">https://github.com/openiddict/openiddict-core/issues/360#issuecomment-280268525</a></p>
  
  <p>This includes creating entity classes extending those given by OpenIddict:</p>
  
  <pre><code>public class CustomApplication : OpenIddictApplication&lt;Guid, CustomAuthorization, CustomToken&gt;
  {
      public string ImpersonateUser { get; set; }
  }
  
  public class CustomAuthorization : OpenIddictAuthorization&lt;Guid, CustomApplication, CustomToken&gt;
  {
  
  }
  
  public class CustomScope : OpenIddictScope&lt;Guid&gt;
  {
  
  }
  
  public class CustomToken : OpenIddictToken&lt;Guid, CustomApplication, CustomAuthorization&gt;
  {
  
  }
  </code></pre>
  
  <p>Updating <code>AddDbContext</code>:</p>
  
  <pre><code>services.AddDbContext&lt;ApplicationContext&gt;(options =&gt;
  {
      options.UseSqlServer(Configuration.GetConnectionString("ConnectionString"));
      options.UseOpenIddict&lt;CustomApplication, CustomAuthorization, CustomScope, CustomToken, Guid&gt;();
  });
  </code></pre>
  
  <p>And a modified version of the call to register the services, to match the newer API:</p>
  
  <pre><code>services.AddOpenIddict()
      .AddCore(options =&gt;
      {
  
          options.UseEntityFrameworkCore().UseDbContext&lt;ApplicationContext&gt;()
              .ReplaceDefaultEntities&lt;CustomApplication, CustomAuthorization, CustomScope, CustomToken, Guid&gt;();
      })
  </code></pre>
  
  <p>Everything appears fine up to this point. Then, as part of application startup, I check for an existing client, and create it if it's not found:</p>
  
  <pre><code>var manager = serviceScope.ServiceProvider.GetRequiredService&lt;OpenIddictApplicationManager&lt;CustomApplication&gt;&gt;();
  
  if (await manager.FindByClientIdAsync("Application") == null) // Throws Here
  {
      var descriptor = new OpenIddictApplicationDescriptor
      {
          ClientId = "Application",
          ClientSecret = "application-default-secret",
          DisplayName = "Application",
          RedirectUris = { new Uri("http://localhost:5000/signin-oidc")},
          Permissions = { OpenIddictConstants.Permissions.Endpoints.Authorization,
              OpenIddictConstants.Permissions.Endpoints.Logout,
              OpenIddictConstants.Permissions.Endpoints.Token,
              OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode,
              OpenIddictConstants.Permissions.GrantTypes.RefreshToken,
              OpenIddictConstants.Permissions.Scopes.Email,
              OpenIddictConstants.Permissions.Scopes.Profile,
              OpenIddictConstants.Permissions.Scopes.Roles}
      };
      await manager.CreateAsync(descriptor);
  }
  </code></pre>
  
  <p>As noted by the "Throws Here" comment, an exception is thrown which is a SqlException:</p>
  
  <pre><code>fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
        Failed executing DbCommand (9ms) [Parameters=[@__identifier='Application' (Size = 100)], CommandType='Text', CommandTimeout='30']
        SELECT TOP(1) [application].[Id], [application].[ClientId], [application].[ClientSecret], [application].[ConcurrencyToken], [application].[ConsentType], [application].[DisplayName], [application].[ImpersonateUser], [application].[Permissions], [application].[PostLogoutRedirectUris], [application].[Properties], [application].[RedirectUris], [application].[Type]
        FROM [OpenIddictApplications] AS [application]
        WHERE [application].[ClientId] = @__identifier
  System.Data.SqlClient.SqlException (0x80131904): Invalid column name 'ImpersonateUser'.
  </code></pre>
  
  <p>It appears somewhere along the way, it's trying to query the old tables instead of the newer ones that I'm specifying. The only things on the callstack for OpenIddict between my seed method, and the SQL exception are <code>OpenIddict.Core.OpenIddictApplicationManager`1.FindByClientIdAsync(String identifier, CancellationToken cancellationToken)</code> and <code>OpenIddict.Core.OpenIddictApplicationCache`1.&lt;&gt;c__DisplayClass6_0.&lt;&lt;FindByClientIdAsync&gt;g__ExecuteAsync|0&gt;d.MoveNext()</code></p>