| | | 1 | | using System.Linq.Expressions; |
| | | 2 | | using Elsa.Identity.Entities; |
| | | 3 | | using Microsoft.EntityFrameworkCore; |
| | | 4 | | using Microsoft.EntityFrameworkCore.ChangeTracking; |
| | | 5 | | using Microsoft.EntityFrameworkCore.Metadata.Builders; |
| | | 6 | | |
| | | 7 | | namespace Elsa.Persistence.EFCore.Modules.Identity; |
| | | 8 | | |
| | | 9 | | internal class Configurations : IEntityTypeConfiguration<User>, IEntityTypeConfiguration<Application>, IEntityTypeConfig |
| | | 10 | | { |
| | 3 | 11 | | private static Expression<Func<ICollection<string>, string>> StringCollectionToStringConverter => v => string.Join(" |
| | 3 | 12 | | private static Expression<Func<string, ICollection<string>>> StringToStringCollectionConverter => v => v.Split(",", |
| | | 13 | | |
| | 1 | 14 | | private static readonly ValueComparer<ICollection<string>> StringCollectionComparer = new( |
| | 1 | 15 | | (c1, c2) => c1!.SequenceEqual(c2!), |
| | 1 | 16 | | c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v.GetHashCode())), |
| | 1 | 17 | | c => c.ToList()); |
| | | 18 | | |
| | | 19 | | public void Configure(EntityTypeBuilder<User> builder) |
| | | 20 | | { |
| | 1 | 21 | | builder.HasIndex(x => x.Name).HasDatabaseName($"IX_{nameof(User)}_{nameof(User.Name)}").IsUnique(); |
| | 1 | 22 | | builder.HasIndex(x => x.TenantId).HasDatabaseName($"IX_{nameof(User)}_{nameof(User.TenantId)}"); |
| | 1 | 23 | | builder.Property(x => x.Roles).HasColumnName("Roles").HasConversion(StringCollectionToStringConverter, StringToS |
| | 1 | 24 | | } |
| | | 25 | | |
| | | 26 | | public void Configure(EntityTypeBuilder<Application> builder) |
| | | 27 | | { |
| | 1 | 28 | | builder.HasIndex(x => x.ClientId).HasDatabaseName($"IX_{nameof(Application)}_{nameof(Application.ClientId)}").Is |
| | 1 | 29 | | builder.HasIndex(x => x.Name).HasDatabaseName($"IX_{nameof(Application)}_{nameof(Application.Name)}").IsUnique() |
| | 1 | 30 | | builder.HasIndex(x => x.TenantId).HasDatabaseName($"IX_{nameof(Application)}_{nameof(Application.TenantId)}"); |
| | 1 | 31 | | builder.Property(x => x.Roles).HasColumnName("Roles").HasConversion(StringCollectionToStringConverter, StringToS |
| | 1 | 32 | | } |
| | | 33 | | |
| | | 34 | | public void Configure(EntityTypeBuilder<Role> builder) |
| | | 35 | | { |
| | 1 | 36 | | builder.HasIndex(x => x.Name).HasDatabaseName($"IX_{nameof(Role)}_{nameof(Role.Name)}").IsUnique(); |
| | 1 | 37 | | builder.HasIndex(x => x.TenantId).HasDatabaseName($"IX_{nameof(Role)}_{nameof(Role.TenantId)}"); |
| | 1 | 38 | | builder.Property(x => x.Permissions).HasColumnName("Permissions").HasConversion(StringCollectionToStringConverte |
| | 1 | 39 | | } |
| | | 40 | | } |