开发者

How to map an NHibernate entity property using both a formula and a column specification

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.

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>

The formula is ignored however, un开发者_高级运维less I remove the <column name="MyThingId" /> line.

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...

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜