views:

227

answers:

3

Hello, I have a table with a time column in my SQL Server 2008 database.

The property of the object I'm trying to map to is a TimeSpan.

How can i tell FluentNHibernate to use the TimeAsTimeSpan NHibernate type, so that I don't have cast problems?

+1  A: 

You should be able to map it using CustomType.

Jamie Ide
What do I put in CustomType? TimeAsTimeSpan or DBType.Time?With TimeAsTimeSpan I get an exception as the type doesn't have a constructor with no parameters
Marnheus
The first line of the linked article is "CustomType("TimeAsTimeSpan") should work fine".
Jamie Ide
+1  A: 

This is working for me:

Map(x => x.TimeFrom)
    .CustomType("TimeAsTimeSpan");
Ian Nelson
A: 

And if you're using the conventions, then this does the job for me:

public class PropertyConvention : IPropertyConvention 
{
    public void Apply(IPropertyInstance instance)
    {
        if (instance.Property.PropertyType == typeof(TimeSpan))
            instance.CustomType( "TimeAsTimeSpan" );
    }
}
David Gardiner