[英]FluentNhibernate, specify or autogenerate Foreign Key field?
I'm learning FluentNHibernate, and until now I haven't specified FKs as property fields, but I let them be auto-generated, from the mappings.我正在学习 FluentNHibernate,直到现在我还没有将 FK 指定为属性字段,但我让它们从映射中自动生成。
But is that sufficient?但这是否足够? It looks to me that in this case, if I want to save some object, I can only save (new objects) by saving the whole aggregate root.
在我看来,在这种情况下,如果我想保存一些 object,我只能通过保存整个聚合根来保存(新对象)。 While I sometimes see it more appropriate to save some lower level objects only.
虽然我有时认为只保存一些较低级别的对象更合适。
So this question I think goes into the use of aggregate roots.所以我认为这个问题涉及到聚合根的使用。 How can they be structured?
它们的结构如何? I thought one aggregate could be part of another aggregate, which would mean you could actually save lower level aggregate without saving the whole root.
我认为一个聚合可能是另一个聚合的一部分,这意味着您实际上可以保存较低级别的聚合而无需保存整个根。 Is this true?
这是真的? And in this case, don't we need to specify the FK if we deal with a newly added entity?
而且在这种情况下,如果我们处理一个新添加的实体,我们是否不需要指定FK? Hence this field must be coded in our classes, and not simply auto-generated as I'm currently doing?
因此这个字段必须在我们的类中编码,而不是像我目前所做的那样简单地自动生成?
If you really want to save a single entity, and not the aggregate root, you will need to define the property that reference the parent entity, allowing you to set it and save the single entity.如果您真的想保存单个实体,而不是聚合根,则需要定义引用父实体的属性,允许您设置它并保存单个实体。 Personally I don't see any issues with it.
就个人而言,我认为它没有任何问题。 Though apparently this is not good DDD practice .
虽然显然这不是好的 DDD 做法。
To save a lower level entity and not it's aggregate root you will need to specify the parent anyways.要保存较低级别的实体而不是聚合根,您无论如何都需要指定父级。 I guess that is why is better to work with the root directly.
我想这就是为什么最好直接使用根。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.