0
votes

I am trying to map a NHibernate formula for a nullable datetime field that would use GetDate() if the column value is null.

The mapping I use is:

Map(x => x.VirtualStartDate).Formula("ISNULL(StartDate, GETDATE ())");

in Fluent NHibernate, which translates to hbm like this:

<property name="VirtualStartDate" formula="ISNULL(StartDate, GETDATE ())" type="System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 

When I try to query the database NHibernate tries to map the built-in GetDate() function to a column in the table:

ISNULL(workitem0_.StartDate, workitem0_.GETDATE()) as formula0_

Which of course doesn't work and returns an SQL error. Is there any way to instruct NHIbernate that this is a built-in SQL function and he should leave it be?

1

1 Answers

1
votes

Just solved it myself, apparently it works if the sql function is written is a lower case form.