如何同时使用公式和列规范来映射NHibernate实体属性 [英] How to map an NHibernate entity property using both a formula and a column specification

查看:66
本文介绍了如何同时使用公式和列规范来映射NHibernate实体属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以这样一种方式映射实体属性,即它将其值写入数据库列,但使用公式来检索其值.

I'm trying to map an entity property in such way that it writes its value to a database column but retrieves its value using a formula.

为了专注于实际问题,我简化了示例.实际上,公式有点复杂,并且使用的是NHibernate过滤器.

To focus on the actual issue, I have simplified the example. In reality the formula is a bit more complex and is using an NHibernate filter.

<many-to-one cascade="all" class="Thing" lazy="false" name="MyThing"
    formula="(SELECT Things.Value FROM Things WHERE Things.Id = MyThingId)">
    <column name="MyThingId" />
</many-to-one>

但是,除非我删除<column name="MyThingId" />行,否则该公式将被忽略.

The formula is ignored however, unless I remove the <column name="MyThingId" /> line.

我如何解决此映射问题,以使NHibernate使用该公式?

How would I fix this mapping in order to have NHibernate use the formula?

推荐答案

我认为不可能完全按照自己的意愿去做.

I don't think it's possible to do exactly what you are trying.

为什么不将属性一分为二?一个对公式为只读,另一个为具有直接列映射的读/写...

Why not split the property in two? One readonly for the formula and the other read/write with a direct column mapping...

如果您仍然想要一个访问点,则可以映射第三个被忽略的属性,该属性使用两个第一个属性来实现它的getset访问器.

If you still want a single access point, you can map a third ignored propery that implements it's get and set accessors with the two first properties.

这篇关于如何同时使用公式和列规范来映射NHibernate实体属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆