在NHibernate,Fluent NHibernate和SQL Server 2008中使用时间列 [英] Using Time columns with NHibernate, Fluent NHibernate and SQL Server 2008

查看:120
本文介绍了在NHibernate,Fluent NHibernate和SQL Server 2008中使用时间列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我试图映射到的对象的属性是TimeSpan。 / p>

如何告诉FluentNHibernate使用TimeAsTimeSpan NHibernate类型,这样我就不会有cast问题了?解决方案

如果你使用的是约定,那么这个工作对我来说就是这样:

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


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?

解决方案

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" );
    }
}

这篇关于在NHibernate,Fluent NHibernate和SQL Server 2008中使用时间列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆