【问题标题】:establishing proper relationship between entities在实体之间建立适当的关系
【发布时间】:2023-03-27 00:08:01
【问题描述】:

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

现在我想建立正确的关系:

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

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 有许多AttributeType(s) via ProfileAttribute 边,通过ProfileAttribute 边我有many to one(许多类型可以属于许多 ProfileAttributes)

【问题讨论】:

    标签: c# nhibernate domain-driven-design


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-30
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      相关资源
      最近更新 更多