diff --git a/src/OpenIddict.EntityFramework/Configurations/OpenIddictApplicationConfiguration.cs b/src/OpenIddict.EntityFramework/Configurations/OpenIddictApplicationConfiguration.cs index abec7341..b12f18b2 100644 --- a/src/OpenIddict.EntityFramework/Configurations/OpenIddictApplicationConfiguration.cs +++ b/src/OpenIddict.EntityFramework/Configurations/OpenIddictApplicationConfiguration.cs @@ -9,7 +9,6 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity.Infrastructure.Annotations; using System.Data.Entity.ModelConfiguration; -using System.Text; using OpenIddict.EntityFramework.Models; namespace OpenIddict.EntityFramework @@ -30,17 +29,6 @@ namespace OpenIddict.EntityFramework { public OpenIddictApplicationConfiguration() { - // Note: unlike Entity Framework Core 1.x/2.x, Entity Framework 6.x - // always throws an exception when using generic types as entity types. - // To ensure a better exception is thrown, a manual check is made here. - if (typeof(TApplication).IsGenericType) - { - throw new InvalidOperationException(new StringBuilder() - .AppendLine("The application entity cannot be a generic type.") - .Append("Consider creating a non-generic derived class.") - .ToString()); - } - // Warning: optional foreign keys MUST NOT be added as CLR properties because // Entity Framework would throw an exception due to the TKey generic parameter // being non-nullable when using value types like short, int, long or Guid. diff --git a/src/OpenIddict.EntityFramework/Configurations/OpenIddictAuthorizationConfiguration.cs b/src/OpenIddict.EntityFramework/Configurations/OpenIddictAuthorizationConfiguration.cs index 39839a38..b03c91d6 100644 --- a/src/OpenIddict.EntityFramework/Configurations/OpenIddictAuthorizationConfiguration.cs +++ b/src/OpenIddict.EntityFramework/Configurations/OpenIddictAuthorizationConfiguration.cs @@ -7,7 +7,6 @@ using System; using System.ComponentModel; using System.Data.Entity.ModelConfiguration; -using System.Text; using OpenIddict.EntityFramework.Models; namespace OpenIddict.EntityFramework @@ -28,17 +27,6 @@ namespace OpenIddict.EntityFramework { public OpenIddictAuthorizationConfiguration() { - // Note: unlike Entity Framework Core 1.x/2.x, Entity Framework 6.x - // always throws an exception when using generic types as entity types. - // To ensure a better exception is thrown, a manual check is made here. - if (typeof(TAuthorization).IsGenericType) - { - throw new InvalidOperationException(new StringBuilder() - .AppendLine("The authorization entity cannot be a generic type.") - .Append("Consider creating a non-generic derived class.") - .ToString()); - } - // Warning: optional foreign keys MUST NOT be added as CLR properties because // Entity Framework would throw an exception due to the TKey generic parameter // being non-nullable when using value types like short, int, long or Guid. diff --git a/src/OpenIddict.EntityFramework/Configurations/OpenIddictScopeConfiguration.cs b/src/OpenIddict.EntityFramework/Configurations/OpenIddictScopeConfiguration.cs index bb917e34..4da122f6 100644 --- a/src/OpenIddict.EntityFramework/Configurations/OpenIddictScopeConfiguration.cs +++ b/src/OpenIddict.EntityFramework/Configurations/OpenIddictScopeConfiguration.cs @@ -9,7 +9,6 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity.Infrastructure.Annotations; using System.Data.Entity.ModelConfiguration; -using System.Text; using OpenIddict.EntityFramework.Models; namespace OpenIddict.EntityFramework @@ -26,17 +25,6 @@ namespace OpenIddict.EntityFramework { public OpenIddictScopeConfiguration() { - // Note: unlike Entity Framework Core 1.x/2.x, Entity Framework 6.x - // always throws an exception when using generic types as entity types. - // To ensure a better exception is thrown, a manual check is made here. - if (typeof(TScope).IsGenericType) - { - throw new InvalidOperationException(new StringBuilder() - .AppendLine("The scope entity cannot be a generic type.") - .Append("Consider creating a non-generic derived class.") - .ToString()); - } - // Warning: optional foreign keys MUST NOT be added as CLR properties because // Entity Framework would throw an exception due to the TKey generic parameter // being non-nullable when using value types like short, int, long or Guid. diff --git a/src/OpenIddict.EntityFramework/Configurations/OpenIddictTokenConfiguration.cs b/src/OpenIddict.EntityFramework/Configurations/OpenIddictTokenConfiguration.cs index 49253bcb..c4d86b93 100644 --- a/src/OpenIddict.EntityFramework/Configurations/OpenIddictTokenConfiguration.cs +++ b/src/OpenIddict.EntityFramework/Configurations/OpenIddictTokenConfiguration.cs @@ -9,7 +9,6 @@ using System.ComponentModel; using System.ComponentModel.DataAnnotations.Schema; using System.Data.Entity.Infrastructure.Annotations; using System.Data.Entity.ModelConfiguration; -using System.Text; using OpenIddict.EntityFramework.Models; namespace OpenIddict.EntityFramework @@ -30,17 +29,6 @@ namespace OpenIddict.EntityFramework { public OpenIddictTokenConfiguration() { - // Note: unlike Entity Framework Core 1.x/2.x, Entity Framework 6.x - // always throws an exception when using generic types as entity types. - // To ensure a better exception is thrown, a manual check is made here. - if (typeof(TToken).IsGenericType) - { - throw new InvalidOperationException(new StringBuilder() - .AppendLine("The token entity cannot be a generic type.") - .Append("Consider creating a non-generic derived class.") - .ToString()); - } - // Warning: optional foreign keys MUST NOT be added as CLR properties because // Entity Framework would throw an exception due to the TKey generic parameter // being non-nullable when using value types like short, int, long or Guid. diff --git a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs index f15b13de..4d00af61 100644 --- a/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs +++ b/src/OpenIddict.EntityFramework/OpenIddictEntityFrameworkBuilder.cs @@ -7,6 +7,7 @@ using System; using System.ComponentModel; using System.Data.Entity; +using System.Text; using JetBrains.Annotations; using Microsoft.Extensions.DependencyInjection.Extensions; using OpenIddict.Core; @@ -63,6 +64,19 @@ namespace Microsoft.Extensions.DependencyInjection where TToken : OpenIddictToken where TKey : IEquatable { + // Note: unlike Entity Framework Core 1.x/2.x/3.x, Entity Framework 6.x + // always throws an exception when using generic types as entity types. + // To ensure a better exception is thrown, a manual check is made here. + if (typeof(TApplication).IsGenericType || typeof(TAuthorization).IsGenericType || + typeof(TScope).IsGenericType || typeof(TToken).IsGenericType) + { + throw new InvalidOperationException(new StringBuilder() + .AppendLine("The Entity Framework 6.x stores cannot be used with generic types.") + .Append("Consider creating non-generic classes derived from the default entities ") + .Append("for the application, authorization, scope and token entities.") + .ToString()); + } + Services.Configure(options => { options.DefaultApplicationType = typeof(TApplication);