22 lines
623 B
C#
22 lines
623 B
C#
using Apimanager_backend.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
|
|
namespace Apimanager_backend.Data
|
|
{
|
|
public class UserRoleConfig : IEntityTypeConfiguration<UserRole>
|
|
{
|
|
public void Configure(EntityTypeBuilder<UserRole> builder)
|
|
{
|
|
builder.HasKey(x => x.Id);
|
|
//自增
|
|
builder.Property(x => x.Id)
|
|
.ValueGeneratedOnAdd();
|
|
//外键
|
|
builder.HasOne(x => x.User)
|
|
.WithMany(u => u.Roles)
|
|
.HasForeignKey(x => x.UserId);
|
|
}
|
|
}
|
|
}
|