Using Time columns with NHibernate, Fluent NHibern

2019-02-12 18:40发布

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?

3条回答
一纸荒年 Trace。
2楼-- · 2019-02-12 18:49

This is working for me:

Map(x => x.TimeFrom)
    .CustomType("TimeAsTimeSpan");
查看更多
趁早两清
3楼-- · 2019-02-12 19:15

You should be able to map it using CustomType.

查看更多
我想做一个坏孩纸
4楼-- · 2019-02-12 19:16

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" );
    }
}
查看更多
登录 后发表回答