ddd 中的多对多关系

发布于 2024-10-16 04:46:16 字数 372 浏览 4 评论 0原文

我有两个聚合根,发布商和营销活动:

  • 1 个营销活动可以注册多个发布商,
  • 1 个发布商可以分配给多个营销活动。

这意味着 MToM 关系

,所以在 Publisher 类中,我创建了

List<Campaign> _campaigns;

,在 Campaign 类中

List<Publisher> _publishers;

,我创建了包含列(id、publisherID、CampaignID)的表,

但我听说应该避免 MtoM,我该怎么做?以上描述正确吗?

I have two Aggregate root, Publisher and Campaign:

  • 1 campaign can have multiple publisher registered,
  • 1 publisher can have assigned to multiple campaign.

that means MToM relationship

so in Publisher class, i created

List<Campaign> _campaigns;

and in Campaign class

List<Publisher> _publishers;

I have created table with columns (id, publisherID,CampaignID)

But i have heard that MtoM should be avoided, how can i do that ? Do above depiction is correct ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掩耳倾听 2024-10-23 04:46:16

确实,您应该避免多对多关系,因为此类关联通常会带来复杂性。实现此目的的一种方法是强制执行遍历方向。因此,在您的域中,如果最常见的操作是针对发布商及其营销活动,您可以认为只有在特殊情况下才需要双向关系,而是在营销活动存储库中使用一种方法来检索给定营销活动的所有发布商。然后,您可以从您的广告活动类别中删除发布商列表

,或者当然反之亦然。

It's true you should avoid many-to-may relationsships, because of the complexity that typically follows such associations. One way to do this is to enforce a traversal direction. So in your domain, if the most common operations is against a publisher and it's campaigns, you could argument that the bidirectional relation is only needed in special cases, and instead have a method on your campaign repository which retrieves all publishers for a given campaign. Then you could remove the list of publishers from your campaign class

Or of course the other way around.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文