开发者

Using built-In SQL functions in NHIbernate Formula

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开发者_C百科 built-in SQL function and he should leave it be?


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜