Separate table for NHibernate Value objects

I am new to DDD and NHibernate.

In my current project, I have a Person object that contains a value object, let it be an address. Today it’s wonderful. But maybe one day I will have a requirement that my value object (in this case Address) should become an entity.

Before trying to simulate this on a DDD path, in a more data-oriented approach, I had a Person table, with Id and another address of the table whose PK was actually FK, it was the identifier Man (i.e. the one-to-one relationship ").

I read that when I map the Value object as a component, its value will appear as columns in my Entity table (so I would not have a one-to-one relationship).

My idea was that if necessary, I would simply add a surrogate key to my address table, and then it would become an entity.

How do I create this using NHibernate? Should I already make the Address object an Entity object?

Sorry, I don’t even know if my questions are clear, I really got lost here.

+4
source share
2 answers

In the system we are building, we put Value objects in separate tables. As far as I know, NHibernate requires the id object to be added to the object, but we ignore this and consider the object as a Value object in the system. As you probably know, a Value object is an object that you don't need to track, so we just skip the id in the object. This makes us freer to model the database the way we want and model the domain model the way we want.

+4
source

You can join and make it a Component that allows nHibernate to match it as the correct value object instead of an entity.

Thus, you do not need virtual properties or an empty protected ctor (it may be closed).

 Join("PROPOSAL_PRODUCT", product => { product.Schema(IsaSchema.PROPOSALOWN); product.KeyColumn("PROPOSAL_ID"); product.Component(Reveal.Member<Proposal, Product>("_product"), proposalProduct => { proposalProduct.Map... }); }); 
0
source

All Articles