在 NHibernate、Fluent NHibernate 和 SQL Server 2008 中使用时间列 [英] Using Time columns with NHibernate, Fluent NHibernate and SQL Server 2008
本文介绍了在 NHibernate、Fluent NHibernate 和 SQL Server 2008 中使用时间列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的 SQL Server 2008 数据库中有一个带有时间列的表.
I have a table with a time column in my SQL Server 2008 database.
我尝试映射到的对象的属性是 TimeSpan.
The property of the object I'm trying to map to is a TimeSpan.
我如何告诉 FluentNHibernate 使用 TimeAsTimeSpan NHibernate 类型,这样我就不会出现转换问题?
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屋!
查看全文