案例:以部门(为主)-----部门下面又分1部、2部、3部等,1部下面又分为1组,2组,3组等这种结构像这样的设计类型应该用自引用来设计下面用用代码来实现:
///
/// Department class
///
public class Department
{
///
/// 部门 Id
///
public int Id { get; set; }
///
/// 部门名称 Name
///
public string Name { get; set; }
///
/// Manager
///
public Department Deparparent { get; set; }
///
///部门下属
///
public ICollection
}
以下是实体模型关系配置类
public class DepartmentConfig : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder
{
builder.ToTable("Department");
builder.Property(d => d.Id).UseIdentityColumn();
builder.Property(d => d.Name).HasMaxLength(50).IsRequired();
builder.HasOne
}
}