Separate table for Value Objects on NHibernate

与世无争的帅哥 提交于 2019-11-30 15:36:28
Fossmo

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.

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...
    });
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!