Files
TechHelper/TechHelper.Server/Context/Configuration/RoleConfiguration.cs
2025-05-23 19:03:00 +08:00

26 lines
660 B
C#

using Entities.Contracts;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace TechHelper.Context.Configuration
{
public class RoleConfiguration : IEntityTypeConfiguration<IdentityRole<Guid>>
{
public void Configure(EntityTypeBuilder<IdentityRole<Guid>> builder)
{
builder.HasData(
Enum.GetValues(typeof(UserRoles))
.Cast<UserRoles>()
.Select(roleEnum => new IdentityRole<Guid>
{
Id = Guid.NewGuid(),
Name = roleEnum.ToString(),
NormalizedName = roleEnum.ToString().ToUpper()
})
.ToArray());
}
}
}