在实体之间建立适当的关系
本文关键字:关系 建立 实体 之间 | 更新日期: 2023-09-27 18:01:12
用户配置文件在系统上具有配置文件属性。这些属性可以是不同的类型(AboutYou、Occupation、AnyhingElse(。
现在我想在以下两者之间建立适当的关系:
- 配置文件和配置文件属性
- 配置文件属性和配置文件属性类型(我不想使用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
的集合似乎很奇怪。也许它会有一个专用类型的属性集合?
就Profile
和ProfileAttribute
之间的关系而言,属性应该是与配置文件聚合关联的值对象。这意味着这种关系是一对多的。换言之,一个概要文件可以包含多个属性,但是一个属性属于单个概要文件。属性本身可以按属性类型分组。如果存在与属性类型相关联的行为,则属性类型本身可以是实体或聚合。