NHibernate mapping: UserTypes with many-to-one

泪湿孤枕 提交于 2019-12-06 07:16:37
theGecko

Looks like I need to use components, can't see how to add references from those or CompositeUserTypes, though :/

https://forum.hibernate.org/viewtopic.php?f=1&t=947719&start=0

https://web.archive.org/web/20090227235136/http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/08/13/a-fluent-interface-to-nhibernate---part-2---value.aspx

http://wiki.fluentnhibernate.org/show/StandardMappingComponents

UPDATE

I have got round this issue by using a CompositeUserType and setting up the proxy endpoint on the entity diring the NullSafeGet() method:

public virtual object NullSafeGet(IDataReader dr, string[] names, ISessionImplementor session, object owner)
{
    if (dr == null)
    {
        return null;
    }

    Money value = new Money()
    {
        Value = (double)NHibernateUtil.Double.NullSafeGet(dr, names[0], session, owner)
    };

    string entityName = session.BestGuessEntityName(value.Currency);
    value.Currency = (CurrencyDetails)session.InternalLoad(entityName, (object)DEFAULT_CURRENCY_ID, false, false);

    return value;
}

Not sure if this is the recommended way of doing it, but it works :)

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