/*
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* See https://github.com/openiddict/openiddict-core for more information concerning
* the license and the contributors participating to this project.
*/
using System.ComponentModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Infrastructure.Annotations;
using System.Data.Entity.ModelConfiguration;
using System.Diagnostics.CodeAnalysis;
using OpenIddict.EntityFramework.Models;
namespace OpenIddict.EntityFramework;
///
/// Defines a relational mapping for the Token entity.
///
/// The type of the Token entity.
/// The type of the Application entity.
/// The type of the Authorization entity.
/// The type of the Key entity.
[EditorBrowsable(EditorBrowsableState.Never)]
public sealed class OpenIddictEntityFrameworkTokenConfiguration<
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TToken,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TApplication,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TAuthorization,
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TKey> : EntityTypeConfiguration
where TToken : OpenIddictEntityFrameworkToken
where TApplication : OpenIddictEntityFrameworkApplication
where TAuthorization : OpenIddictEntityFrameworkAuthorization
where TKey : notnull, IEquatable
{
public OpenIddictEntityFrameworkTokenConfiguration()
{
// 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.
HasKey(token => token.Id);
Property(token => token.ConcurrencyToken)
.HasMaxLength(50)
.IsConcurrencyToken();
// Warning: the index on the ReferenceId property MUST NOT be declared as
// a unique index, as Entity Framework 6.x doesn't support creating indexes
// with null-friendly WHERE conditions, unlike Entity Framework Core.
Property(token => token.ReferenceId)
.HasMaxLength(100)
.HasColumnAnnotation(IndexAnnotation.AnnotationName, new IndexAnnotation(new IndexAttribute()));
Property(token => token.Status)
.HasMaxLength(50);
Property(token => token.Subject)
.HasMaxLength(400);
Property(token => token.Type)
.HasMaxLength(150);
ToTable("OpenIddictTokens");
}
}