本文介绍了如何处理来自SQL Server 2008与NHibernate的TIME数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SQL Server 2008中的 TIME 数据类型,并且在使用NHibernate时遇到一些问题。

  public TimeTableEventMap()
{
Id(x => x.Id)
Map(x => x.Day) .NvarcharWithMaxSize()Not.Nullable();
Map(x => x.StartTime).Length(4).TimeDataType()。Not.Nullable();
Map(x => x.Endtime).Length(4).TimeDataType()。Not.Nullable();
References(x => x.TimeTable).Not.Nullable()。Cascade.All();
引用(x => x.RequiredSettings).Not.Nullable()。Cascade.All();
}

///< summary>
/// MS Sql 2008日期类型。
///< / summary>
///< param name =map>< / param>
///<返回>< /返回>
public static PropertyPart TimeDataType(this PropertyPart map)
{
return map.CustomSqlType(time);
}

public class TimeTableEvent
{
public virtual int Id {get;私人设置}
public virtual DayOfWeek Day {get;组; }
public virtual DateTime StartTime {get;组; }
public virtual DateTime Endtime {get;组; }
public virtual TimeTable TimeTable {get;组; }
public virtual RequiredSetting RequiredSettings {get;组; }
}

我得到这个错误



  public List< TimeTableEvent> GetTimeTableEvents(Student student,List< int> timeTableIds)
{
TimeTableEvent tAlias = null;

List< TimeTableEvent> (限制.In(Projections.Property(()=> tAlias.TimeTable.Id),timeTableIds))
(all_accounts = session.QueryOver< TimeTableEvent>(()=> tAlias) .Fetch(r => r.RequiredSettings).Eager
.TransformUsing(Transformers.DistinctRootEntity)
.Take(QueryLimits.TimeTableEvents)
.List< TimeTableEvent>()ToList ;

返回allEvents;


解决方案


I am using the TIME datatype from SQL Server 2008 and I am having some problems getting it to work with NHibernate.

public TimeTableEventMap()
{
    Id(x => x.Id)
    Map(x => x.Day).NvarcharWithMaxSize().Not.Nullable();
    Map(x => x.StartTime).Length(4).TimeDataType().Not.Nullable();
    Map(x => x.Endtime).Length(4).TimeDataType().Not.Nullable();
    References(x => x.TimeTable).Not.Nullable().Cascade.All();
    References(x => x.RequiredSettings).Not.Nullable().Cascade.All();
}

/// <summary>
///  MS Sql 2008 date type.
/// </summary>
/// <param name="map"></param>
/// <returns></returns>
public static PropertyPart TimeDataType(this PropertyPart map)
{
   return map.CustomSqlType("time");
}

public class TimeTableEvent
{
    public virtual int Id { get; private set; }
    public virtual DayOfWeek Day { get; set; }
    public virtual DateTime StartTime { get; set; }
    public virtual DateTime Endtime { get; set; }
    public virtual TimeTable TimeTable { get; set; }
    public virtual RequiredSetting RequiredSettings { get; set; }
}

I get this error

public List<TimeTableEvent> GetTimeTableEvents(Student student, List<int> timeTableIds)
{
    TimeTableEvent tAlias = null;

    List<TimeTableEvent> allEvents = session.QueryOver<TimeTableEvent>(() => tAlias)
        .Where(Restrictions.In(Projections.Property(() => tAlias.TimeTable.Id), timeTableIds))
        .Fetch(r => r.RequiredSettings).Eager
        .TransformUsing(Transformers.DistinctRootEntity)
        .Take(QueryLimits.TimeTableEvents)
        .List<TimeTableEvent>().ToList();

    return allEvents;
}
解决方案

Date/Time Support in NHibernate

这篇关于如何处理来自SQL Server 2008与NHibernate的TIME数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 06:22