是这样的值对象 [英] is this value object
问题描述
一文有消息。所以我而言,我应该如何构建消息
对象的窘境。作为实体或值对象有DDD记方法。
消息
不应该被跟踪过独立的,不文章
对象。据我所知的值对象没有身份,知道我怎么可以跟踪物品的信息?
如果我的POCO是
公共类文章{
公众诠释ID {获得;组;}
公共字符串名称{;组;}
公开消息消息{获得;组;}
}
公共类消息{
公共字符串身体{获得;组;}
}
我应该添加文章内的信息来建立物品信息跟踪。如果我添加到条消息类做我打破值对象定义?
更新: 我的目标是让访问者留下消息(S),以特定的文章。信息不应该被单独追踪,但应跟踪低谷文章对象。
我而言,我应该如何构建Message对象困境
最起码应该是:
公共类信息
{
公众诠释编号{获得;集;} //的MessageId
公共逐条{获得;组; } // 所有者
公共字符串身体{获得;组;}
}
根据您的框架,你可能需要添加/管理外键的属性也是如此。 EF就明白了:
公共类信息
{
公众诠释编号{获得;集;} //的MessageId
//使用虚拟的关键字和/或增加一个条款ArticleID和/或使用某些属性。
公众诠释条款ArticleID {获得;组; }
公共虚拟逐条{获得;组; } // 所有者
公共字符串身体{获得;组;}
}
one article has messages. So I have dilemma in terms how should I construct Message
object. As entity or value object having ddd approach in mind.
Message
should not be ever tracked independent, without Article
object. As far as I know value object have no identity, and knowing that how can I track article messages?
If my poco is
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;}
}
should I add Article inside Message to establish tracking of article message. If I add Article to Message class do I break Value object definition?
Update: my goal is to allow visitors to leave message(s) to specific article. Message should not be tracked independently but should be tracked trough article object.
I have dilemma in terms how should I construct Message object
At the very least it should be:
public class Message
{
public int Id {get; set;} // MessageId
public Article Article { get; set; } // Owner
public string body {get; set;}
}
depending on your framework, you may want to add/manage the foreign key property as well. EF will understand:
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;}
}
这篇关于是这样的值对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!