Iresh
Iresh

Reputation: 91

How to Check column value null or not before Map in property in Nhibernate

I have a property called MyValue. Need to map column value("Total") to that property. before mapping need to check whether column value null or not. If null, map another column value("Count") to that.

How do I proceed this,

this is done for Total Value

 Map(x => x.MyValue)
       .Column("Total")
       .CustomType("Decimal")
       .Access.Property()
       .Generated.Never()
       .CustomSqlType("decimal")
       .Precision(9).Scale(2);

Upvotes: 0

Views: 827

Answers (1)

Radim Köhler
Radim Köhler

Reputation: 123861

In case that you are talking about having two columns in DB and want to work with them on Application tier as one ... you should map them with FORMULA.

 Map(x => x.MyValue)
       //.Column("Total")
       .Formula("ISNULL(Total, Count)")
       ...

NOTE: that should always be treated as readonly - if you need to write to both columns, map them separately, and create this third readonly mapping for the ISNULL formula...

Check the doc: 5.1.10. property

Upvotes: 4

Related Questions