Separate table for Value Objects on NHibernate

前端 未结 2 1912
野的像风
野的像风 2021-01-03 07:01

I\'m new to DDD and NHibernate.

In my current project, I have an entity Person, that contains a value object, let\'s say Address. Today, this is fine. But maybe one

相关标签:
2条回答
  • 2021-01-03 07:17

    In the system we are building, we put Value-Objects in separate tables. As far as I know, NHibernate requires that an id must added to the object, but we ignore this and treat 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 simply overlook 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.

    0 讨论(0)
  • 2021-01-03 07:28

    You can Join and make it a Component allowing nHibernate to map it as a proper value object instead of an entity.

    This way you won't need any virtual properties nor an empty protected ctor (it can be private).

    Join("PROPOSAL_PRODUCT", product =>
    {
        product.Schema(IsaSchema.PROPOSALOWN);
        product.KeyColumn("PROPOSAL_ID");
    
        product.Component(Reveal.Member<Proposal, Product>("_product"), proposalProduct =>
        {
            proposalProduct.Map...
        });
    });
    
    0 讨论(0)
提交回复
热议问题