42 lines
1.2 KiB
C#
42 lines
1.2 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using Nocr.Users.AppServices.Users;
|
|
|
|
namespace Nocr.Users.Persistence.Users;
|
|
|
|
public class UserConfiguration : IEntityTypeConfiguration<User>
|
|
{
|
|
public void Configure(EntityTypeBuilder<User> builder)
|
|
{
|
|
builder.HasKey(x => x.Id);
|
|
builder.Property(x => x.Username)
|
|
.IsRequired();
|
|
|
|
builder.Property(x => x.BotBlocked)
|
|
.HasDefaultValue(false);
|
|
|
|
builder.HasIndex(x => x.Username)
|
|
.IsUnique()
|
|
.HasDatabaseName("UX_users_username");
|
|
|
|
builder
|
|
.HasMany(u => u.Identities)
|
|
.WithOne()
|
|
.HasForeignKey(x => x.UserId)
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
}
|
|
}
|
|
|
|
public class UserIdentityConfiguration : IEntityTypeConfiguration<UserIdentity>
|
|
{
|
|
public void Configure(EntityTypeBuilder<UserIdentity> builder)
|
|
{
|
|
builder.HasKey(x => x.Id);
|
|
builder.Property(x => x.Identity)
|
|
.IsRequired();
|
|
|
|
builder.HasIndex(x => new { x.Identity, x.Type })
|
|
.IsUnique()
|
|
.HasDatabaseName("UX_users_identity_identity_type");
|
|
}
|
|
} |