开发者

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.

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. 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? 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.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜