diff --git a/integrations/entity-framework.html b/integrations/entity-framework.html new file mode 100644 index 0000000..69cad8b --- /dev/null +++ b/integrations/entity-framework.html @@ -0,0 +1,197 @@ + + + + + + + + + Entity Framework 6.x integration + + + + + + + + + + + + + + + + + + +
+ + + + + + + + OpenIddict + OpenIddict + +
+ +
+ +
+ +
+ +
+ + + + +
+ + + OpenIddict + OpenIddict + +
+ +
+ +
+ + +
+ + +
+
+
+ +
+ +
+ + Generated by DocFX +
+
+ +
+ +
+ + +
+
+
    +
  • +
+
+
+ +
+

Entity Framework 6.x integration

+ +

Basic configuration

+

To configure OpenIddict to use Entity Framework 6.x as the database for applications, authorizations, scopes and tokens, you'll need to:

+
    +
  • Reference the OpenIddict.EntityFramework package:

    +
    <PackageReference Include="OpenIddict.EntityFramework" Version="3.1.1" />
    +
  • +
  • Create a database context deriving from DbContext and register the OpenIddict entities in the model:

    +
    public class ApplicationDbContext : DbContext
    +{
    +    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    +    {
    +        base.OnModelCreating(modelBuilder);
    +
    +        modelBuilder.UseOpenIddict();
    +    }
    +}
    +
  • +
  • Configure OpenIddict to use the Entity Framework 6.x stores:

    +
    services.AddOpenIddict()
    +    .AddCore(options =>
    +    {
    +        options.UseEntityFramework()
    +               .UseDbContext<ApplicationDbContext>();
    +    });
    +
  • +
  • Use migrations or recreate the database to add the OpenIddict entities. +For more information, read Code First Migrations.

    +
  • +
+

Advanced configuration

+

Use a custom primary key type

+

By default, the Entity Framework 6.x integration uses string primary keys, which matches the default key type used by ASP.NET Identity.

+
Warning

Unlike Entity Framework Core, Entity Framework 6.x doesn't support closed generic types, which prevents using the OpenIddict entities +without subclassing them. As such, using a custom primary key type is a bit more complicated with Entity Framework 6.x than with +Entity Framework Core and requires implementing custom entities, as highlighted in the next section.

+
+

Use custom entities

+

For applications that require storing additional data alongside the properties used by OpenIddict, custom entities can be used. For that, you need to:

+
    +
  • Create custom entities:

    +
    public class CustomApplication : OpenIddictEntityFrameworkApplication<long, CustomAuthorization, CustomToken>
    +{
    +    public string CustomProperty { get; set; }
    +}
    +
    +public class CustomAuthorization : OpenIddictEntityFrameworkAuthorization<long, CustomApplication, CustomToken>
    +{
    +    public string CustomProperty { get; set; }
    +}
    +
    +public class CustomScope : OpenIddictEntityFrameworkScope<long>
    +{
    +    public string CustomProperty { get; set; }
    +}
    +
    +public class CustomToken : OpenIddictEntityFrameworkToken<long, CustomApplication, CustomAuthorization>
    +{
    +    public string CustomProperty { get; set; }
    +}
    +
  • +
  • Call the generic ReplaceDefaultEntities<TApplication, TAuthorization, TScope, TToken, TKey>() method to force OpenIddict to use the custom entities:

    +
    services.AddOpenIddict()
    +    .AddCore(options =>
    +    {
    +        // Configure OpenIddict to use the custom entities.
    +        options.UseEntityFramework()
    +               .UseDbContext<ApplicationDbContext>()
    +               .ReplaceDefaultEntities<CustomApplication, CustomAuthorization, CustomScope, CustomToken, long>();
    +    });
    +
  • +
  • Register the custom entities in the model:

    +
    public class ApplicationDbContext : DbContext
    +{
    +    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    +    {
    +        base.OnModelCreating(modelBuilder);
    +
    +        modelBuilder.UseOpenIddict<CustomApplication, CustomAuthorization, CustomScope, CustomToken, long>();
    +    }
    +}
    +
  • +
+
+ +
+
+
+ + + + + + + + + + + + + + + diff --git a/integrations/toc.html b/integrations/toc.html index d30f2e4..9137e03 100644 --- a/integrations/toc.html +++ b/integrations/toc.html @@ -8,6 +8,10 @@
  • Introduction +
  • +
  • + Entity Framework +
  • Entity Framework Core diff --git a/manifest.json b/manifest.json index 0da9169..a8fb7fc 100644 --- a/manifest.json +++ b/manifest.json @@ -1688,6 +1688,18 @@ "is_incremental": false, "version": "" }, + { + "type": "Conceptual", + "source_relative_path": "integrations/entity-framework.md", + "output": { + ".html": { + "relative_path": "integrations/entity-framework.html", + "hash": "3Lp7rwhlg8lOZwXEHiRplA==" + } + }, + "is_incremental": false, + "version": "" + }, { "type": "Conceptual", "source_relative_path": "integrations/index.md", @@ -1718,7 +1730,7 @@ "output": { ".html": { "relative_path": "integrations/toc.html", - "hash": "914frhil++hv0x3ddB061A==" + "hash": "D9pwWOpK/ZMU1O/IKUo29Q==" } }, "is_incremental": false, @@ -2433,7 +2445,7 @@ "ConceptualDocumentProcessor": { "can_incremental": false, "incrementalPhase": "build", - "total_file_count": 134, + "total_file_count": 135, "skipped_file_count": 0 }, "ResourceDocumentProcessor": {