Sandor Drieënhuizen
Sandor Drieënhuizen

Reputation: 6388

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, unless I remove the <column name="MyThingId" /> line.

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

Upvotes: 0

Views: 1343

Answers (1)

Variant
Variant

Reputation: 17375

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.

Upvotes: 6

Related Questions