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