在NHibernate,Fluent NHibernate和SQL Server 2008中使用Time列

Gui*_*ion 9 nhibernate nhibernate-mapping fluent-nhibernate sql-server-2008

我的SQL Server 2008数据库中有一个包含时间列的表.

我想要映射到的对象的属性是TimeSpan.

我如何告诉FluentNHibernate使用TimeAsTimeSpan NHibernate类型,以便我没有演员问题?

Ian*_*son 7

这对我有用:

Map(x => x.TimeFrom)
    .CustomType("TimeAsTimeSpan");
Run Code Online (Sandbox Code Playgroud)

  • @ mindplay.dk`TimeSpan`不能代表`null`.`TimeSpan?`可以. (3认同)

Dav*_*ner 5

如果你正在使用这些约定,那么这对我有用:

public class PropertyConvention : IPropertyConvention 
{
    public void Apply(IPropertyInstance instance)
    {
        if (instance.Property.PropertyType == typeof(TimeSpan))
            instance.CustomType( "TimeAsTimeSpan" );
    }
}
Run Code Online (Sandbox Code Playgroud)