使用 EF 4.1,复杂类型是否可以引用实体(例如,在 DDD 中,值对象引用实体)?
一篇博客文章我读过似乎表明值对象可以在域驱动设计中引用实体,并且 后续解释了如何做这在 NHibernate 中。
我想使用 Entity Framework 4.1 做同样的事情:具体来说,有一个复杂类型引用另一个实体。举个例子,考虑一下:我有一个实体,比方说,Invoice,它具有 Total 类型为 Currency 的属性。 Currency 是一个复杂类型,包含一个名为 Value 的 decimal
类型属性和一个 Unit 类型属性货币单位。 CurrencyUnit 是“参考数据实体”。也就是说,此特定域中的 CurrencyUnit 是一个实体,而不是值对象本身。
现在,虽然 DDD 中可能“允许”,但这不是我的偏好;我不想争论优劣。我有兴趣了解 EF 中是否有代码优先的解决方案来处理这种情况。我似乎找不到任何东西,这很奇怪,因为复杂类型映射到其实体的包含表,当然可以有外键引用。
A blog entry I read seems to indicate it's ok for value objects to reference entities in domain driven design, and the follow-up explains how to do this in NHibernate.
I would like to do the same thing using Entity Framework 4.1: specifically, have a complex type reference another entity. As an example consider this: I have an entity, let's say, Invoice that has a Total property of type Currency. Currency is a complex type containing a property of type decimal
called Value and a Unit property of type CurrencyUnit. CurrencyUnit is a "reference data entity". That is, CurrencyUnit in this particular domain is an entity, not a value object itself.
Now while possibly "allowed" in DDD, it's not my preference; I don't want to debate the merits. I'm interested in learning if there is a code-first solution in EF to handle this scenario. I can't seem to find anything, which is odd since complex types map to their entity's containing table, which can of course have foreign key references.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Crud(没有双关语)我刚刚发现这个问题,其答案表明它根本没有在 EF 4.1 中实现:具有导航属性的 EF4 复杂类型(是否可能) )或替代方案?
Crud (no pun intended) I just found this question whose answer indicates its simply not implemented in EF 4.1: EF4 complex type with navigation property (is it possible) or alternatives?