Seb
Seb

Reputation: 830

Fluent nHibernate CustomType for SQL2008 date and time types

I'm puzzled by some code I wrote by mistake that works...

        Map( x => x.StartTime )
            .Access.Property()
            .CustomType( "time" )
            .Generated.Never()
            .Column( "StartTime" )
            .Default( "(CONVERT([time],getdate(),(0)))" )
            .Nullable()
            .Not.LazyLoad();

For some reason it works just fine, but when I realised I meant to write CustomSqlType instead of CustomType and changed it, it stopped working... also, if I just remove the line CustomType( "time" ) it also stops working. The only way to make it work is to have it the way it is above, and I don't understand why :(

Edit: forgot to mention that on the SQL side my column is of type "time" and on the .NET side the property is of type DateTime? (nullable).

Upvotes: 1

Views: 720

Answers (1)

Firo
Firo

Reputation: 30813

NHibernate uses ITypes to marshal back and forth property types to column values. There are several builtin Types to use for example the NHibernate.Type.TimeType which has the name "time".

Upvotes: 1

Related Questions