开发者

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

开发者 https://www.devze.com 2023-03-15 02:28 出处:网络
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.

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

精彩评论

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

关注公众号