Tigraine

Daniel Hoelbling-Inzko talks about programming

Mappin Sql-Time to TimeSpan with NHibernate

Posted by Daniel Hölbling on May 12, 2011

Funny how long you can use NHibernate + Fluent NHibernate on greenfield applications and not use all of it’s mapping features. But one little project that needs to talk to a legacy database and you run into all kinds of troubles.

Today I had to map the time datatype present in MsSql2008. According to official Microsoft documentation the preferred clr-type for time is TimeSpan.

Unfortunately, by default NHibernate believes that the best way to map TimeSpan is to transform it to a bigint.

Fortunately the solution is rather trivial:

Map(p => p.CreatedOn, "CreationTime")
.CustomType("TimeAsTimeSpan");

Filed under net, programmierung, nhibernate
comments powered by Disqus

My Photography business

Projects

dynamic css for .NET

Archives

more