在实体之间建立适当的关系

本文关键字:关系 建立 实体 之间 | 更新日期: 2023-09-27 18:01:12

用户配置文件在系统上具有配置文件属性。这些属性可以是不同的类型(AboutYou、Occupation、AnyhingElse(。

现在我想在以下两者之间建立适当的关系:

  1. 配置文件和配置文件属性
  2. 配置文件属性和配置文件属性类型(我不想使用enum作为数据类型(

Profile.cs

public List<ProfileAttribute> Attributes {get; set;}

ProfileAttribute.cs

// holds user entered response on particular subject
// describe yourself (if aboutYou type is selected)
public string Response {get; set;}
public ProfileAttributeType {get; set;}

ProfileAttributeType.cs

public List<ProfileAttribute> Attributes {get; set;}
public string AttributeType {get; set;}

这是遗留代码和数据库,我正试图使用ddd方法和生成的数据库表来构建应用程序,所以我只关注以下内容。

一个Profile具有多个ProfileAttribute。所以我有one to many通过侧面。

我无法通过ProfileAttribute侧来计算关系。所有配置文件属性属于一个配置文件还是属于many to many?这个Response属性让我很困惑。你会怎么做?

此外,对于ProfileAttribute和ProfileAttributeType,我有以下

一个ProfileAttribute通过ProfileAttribute侧具有多个AttributeType,通过ProfileAttribute侧具有many to one(许多类型可以属于多个ProfileAttribute(

在实体之间建立适当的关系

首先,ProfileAttributeType本身包含ProfileAttribute的集合似乎很奇怪。也许它会有一个专用类型的属性集合?

ProfileProfileAttribute之间的关系而言,属性应该是与配置文件聚合关联的值对象。这意味着这种关系是一对多的。换言之,一个概要文件可以包含多个属性,但是一个属性属于单个概要文件。属性本身可以按属性类型分组。如果存在与属性类型相关联的行为,则属性类型本身可以是实体聚合