gpt4 book ai didi

c# - 是这个值对象

转载 作者:太空宇宙 更新时间:2023-11-03 16:01:21 29 4
gpt4 key购买 nike

一篇文章有​​留言。所以我在如何构造 Message 对象方面遇到了两难境地。作为具有 ddd 方法的实体或值对象。

Message 不应在没有 Article 对象的情况下独立跟踪。据我所知值对象没有标识,并且知道如何跟踪文章消息?

如果我的poco是

public class Article {
public int id {get; set;}
public string Name {get; set;}
public Message Message {get; set;}
}

public class Message{
public string body {get; set;}
}

我是否应该在 Message 中添加 Article 以建立对文章消息的跟踪。如果我将 Article 添加到 Message 类,是否会破坏 Value 对象定义?

更新:我的目标是让访问者给特定文章留言。不应单独跟踪消息,而应通过文章对象进行跟踪。

最佳答案

I have dilemma in terms how should I construct Message object

至少应该是:

public class Message
{
public int Id {get; set;} // MessageId
public Article Article { get; set; } // Owner
public string body {get; set;}
}

根据您的框架,您可能还想添加/管理外键属性。 EF 会理解:

public class Message
{
public int Id {get; set;} // MessageId

// use the 'virtual' keyword and/or add an ArticleId and/or use some Attributes.
public int ArticleId { get; set; }
public virtual Article Article { get; set; } // Owner
public string body {get; set;}
}

关于c# - 是这个值对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21195697/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com