25 lines
782 B
C#
25 lines
782 B
C#
using Domain.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace Infrastructure.Configuration;
|
|
|
|
public class UserRoleConfiguration : IEntityTypeConfiguration<UserRole>
|
|
{
|
|
public void Configure(EntityTypeBuilder<UserRole> builder)
|
|
{
|
|
builder.ToTable("UserRoles", "auth");
|
|
builder.HasKey(x => new { x.UserId, x.RoleId });
|
|
builder.HasOne(x => x.User)
|
|
.WithMany(x => x.UserRoles)
|
|
.HasForeignKey(x => x.UserId);
|
|
|
|
builder.HasOne(x => x.Role)
|
|
.WithMany(x => x.UserRoles)
|
|
.HasForeignKey(x => x.RoleId);
|
|
|
|
builder.HasData(
|
|
new UserRole { UserId = 1, RoleId = 1 },
|
|
new UserRole { UserId = 2, RoleId = 2 });
|
|
}
|
|
} |