FluentNHibernate Formula Mapping C#

1.4k Views Asked by At

Is there a way to declare a map passing a Formula which will run just for a specific statement (SELECT in my case)?

The problem is that I have something like

Map(x => x.Id).Formula("SUBSTRING(id, 0, 2)");

But it's causing errors when I try to run an insert for this specific entity, because it's using the Formula for the insert statement as well.

1

There are 1 best solutions below

2
On

We have to make such column readonly

Map(x => x.Id)
    .Formula("SUBSTRING(id, 0, 2)")
    .ReadOnly();

or more like original insert="false" udpate="false"

Map(x => x.Id)
    .Formula("SUBSTRING(id, 0, 2)")
    .Not.Update()
    .Not.Insert();