值对象如何保存和加载? [英] How value objects are saved and loaded?
问题描述
因为没有值对象的存储库. 如何加载所有值对象?
Since there aren no respositories for value objects. How can I load all value objects?
假设我们正在对博客应用程序进行建模,并且具有此类:
Suppose we are modeling a blog application and we have this classes:
- 发布(实体)
- 注释(值对象)
- 标签(值对象)
- PostsRespository(存储库)
我知道,当我保存新帖子时,其标签将与之一起保存在同一表格中.但是我如何加载所有帖子的所有标签. PostsRespository是否应该有一种加载所有标签的方法? 我通常会这样做,但我想了解其他人的意见
I Know that when I save a new post, its tags are saved with it in the same table. But how could I load all tags of all posts. Should PostsRespository have a method to load all tags? I usually do it, but I want to know others opinions
推荐答案
我正在为这个问题寻找更好的解决方案,而我发现了这篇文章:
I'm looking for a better solution for this question and I found this post:
http://gojko .net/2009/09/30/ddd-and-relational-databases-value-object-dilemma/
这篇文章很好地解释了为什么对价值对象和数据库有很多困惑. 在这里,您是一个非常喜欢我的短语:
This post explain very well why there is a lot of confusion with value objects and databases. Here you are phrase which liked me too much:
- "持久性不是将一切都变成实体的借口."
Gojko Adzic,给我们三种选择来保存我们的价值对象.
Gojko Adzic, give us three alternatives to save our value objects.
这篇关于值对象如何保存和加载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!