這些變更為 `Account`、`Department` 和 `Role` 實體配置資料庫結構。每個配置類別實作了 `IEntityTypeConfiguration<T>` 介面,並在 `Configure` 方法中定義了主鍵、欄位名稱、必填性和最大長度等屬性。此外,為 `Account` 實體設置了索引和外鍵關聯,以確保資料的完整性和唯一性。
24 lines
633 B
C#
24 lines
633 B
C#
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|
using Models.Entities;
|
|
|
|
namespace Configurations
|
|
{
|
|
public class RoleConfiguration : IEntityTypeConfiguration<Role>
|
|
{
|
|
public void Configure(EntityTypeBuilder<Role> builder)
|
|
{
|
|
builder.ToTable("roles");
|
|
|
|
builder.HasKey(r => r.RoleId);
|
|
|
|
builder.Property(r => r.RoleId)
|
|
.HasColumnName("role_id");
|
|
|
|
builder.Property(r => r.RoleName)
|
|
.HasColumnName("role_name")
|
|
.IsRequired()
|
|
.HasMaxLength(50);
|
|
}
|
|
}
|
|
} |