RIA域服务返回null,尽管NHibernate DAL返回数据

RIA域服务返回null,尽管NHibernate DAL返回数据,nhibernate,ria,Nhibernate,Ria,嗨,我的NHibernate DAL中有以下方法: public IQueryable<WorkCellLoadGraphData> GetWorkCellLoadGraphDataById( string workCellId, DateTime startDate, DateTime endDate ) { var workCellGraphData = ( from x in this.GetSession().Query<WorkCellLoa

嗨,我的NHibernate DAL中有以下方法:

 public IQueryable<WorkCellLoadGraphData> GetWorkCellLoadGraphDataById( string workCellId, DateTime startDate, DateTime endDate )
    {
        var workCellGraphData = ( from x in this.GetSession().Query<WorkCellLoadGraphData>()
                  where x.WorkCellId == workCellId && (x.FromTime >= startDate && x.FromTime <= endDate)
                  select new
                             {
                                 x.WorkCellId,
                                 x.CalendarId,
                                 x.FromTime,
                                 x.DurationInMinutes
                             });

        return workCellGraphData as IQueryable<WorkCellLoadGraphData>;
    }
public IQueryable GetWorkCellLoadGraphDataById(字符串workCellId、DateTime startDate、DateTime endDate)
{
var workCellGraphData=(此.GetSession().Query()中的x)

其中x.WorkCellId==WorkCellId&&(x.FromTime>=startDate&&x.FromTime我不确定区别是什么,但我们使用以下方法解决了这个特定问题:

 public IList<WorkCellLoadGraphData> GetWorkCellLoadGraphDataByIdA(string workCellId, DateTime startDate, DateTime endDate)
    {
        IList<WorkCellLoadGraphData> results = new List<WorkCellLoadGraphData>();

        using (var session = this.GetSession())
        {

            var criteria = session.CreateCriteria(typeof(WorkCellLoadGraphData));

            criteria.SetProjection(
                Projections.ProjectionList()
                    .Add(Projections.Property(WorkCellLoadGraphData.WorkCellIdPropertyName), "WorkCellId")

                    .Add(Projections.Property(WorkCellLoadGraphData.FromTimePropertyName), "FromTime")
                    .Add(Projections.Property(WorkCellLoadGraphData.DurationPropertyName), "DurationInMinutes")
                    .Add( Projections.Property( WorkCellLoadGraphData.CalendarIdPropertyName), "CalendarId" )

                );

            criteria.Add(Restrictions.InsensitiveLike(WorkCellLoadGraphData.WorkCellIdPropertyName, workCellId));
            criteria.Add(Restrictions.Between(WorkCellLoadGraphData.FromTimePropertyName, startDate, endDate));

            criteria.SetResultTransformer(new AliasToBeanResultTransformer(typeof(WorkCellLoadGraphData)));

            results = criteria.List<WorkCellLoadGraphData>();
        }

                return results;
    }
public IList GetWorkCellLoadGraphDataByIdA(字符串workCellId、DateTime startDate、DateTime endDate)
{
IList results=新列表();
使用(var session=this.GetSession())
{
var-criteria=session.CreateCriteria(typeof(WorkCellLoadGraphData));
标准.SetProjection(
投影。投影列表()
.Add(Projections.Property(WorkCellLoadGraphData.WorkCellIdPropertyName),“WorkCellId”)
.Add(Projections.Property(WorkCellLoadGraphData.FromTimePropertyName),“FromTime”)
.Add(Projections.Property(WorkCellLoadGraphData.DurationPropertyName),“DurationInMinutes”)
.Add(Projections.Property(WorkCellLoadGraphData.CalendarIdPropertyName),“CalendarId”)
);
条件.Add(限制.InsensitiveLike(WorkCellLoadGraphData.WorkCellIdPropertyName,workCellId));
添加(限制.Between(WorkCellLoadGraphData.FromTimePropertyName、startDate、endDate));
标准.SetResultTransformer(新别名为BeanResultTransformer(类型为(WorkCellLoadGraphData)));
结果=标准。列表();
}
返回结果;
}

至少可以说,这真的令人费解…

在LINQ中,查询的执行通常会推迟到您实际请求数据的那一刻。 在第一种方法中,您只定义了查询,但它从未被执行;在第二种方法中,只要您需要枚举结果,它就会被执行

 public IList<WorkCellLoadGraphData> GetWorkCellLoadGraphDataByIdA(string workCellId, DateTime startDate, DateTime endDate)
    {
        IList<WorkCellLoadGraphData> results = new List<WorkCellLoadGraphData>();

        using (var session = this.GetSession())
        {

            var criteria = session.CreateCriteria(typeof(WorkCellLoadGraphData));

            criteria.SetProjection(
                Projections.ProjectionList()
                    .Add(Projections.Property(WorkCellLoadGraphData.WorkCellIdPropertyName), "WorkCellId")

                    .Add(Projections.Property(WorkCellLoadGraphData.FromTimePropertyName), "FromTime")
                    .Add(Projections.Property(WorkCellLoadGraphData.DurationPropertyName), "DurationInMinutes")
                    .Add( Projections.Property( WorkCellLoadGraphData.CalendarIdPropertyName), "CalendarId" )

                );

            criteria.Add(Restrictions.InsensitiveLike(WorkCellLoadGraphData.WorkCellIdPropertyName, workCellId));
            criteria.Add(Restrictions.Between(WorkCellLoadGraphData.FromTimePropertyName, startDate, endDate));

            criteria.SetResultTransformer(new AliasToBeanResultTransformer(typeof(WorkCellLoadGraphData)));

            results = criteria.List<WorkCellLoadGraphData>();
        }

                return results;
    }