开发者

RIA Domain service returns null although NHibernate DAL returns data

Hi I've got the following method in my 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>;
    }

When I put a breakpoint on workCellGraphData, I get a collection of WorkCellGraphData objects.

However, the calling code, in the RIA domain service class, to this method which is:

 public IQueryable<WorkCellLoadGraphData> GetWorkCellLoadGraphDataById()
    {          
        IQueryable<WorkCellLoadGraphData> result = ManufacturingDao.Instance.GetWorkCellLoadGraphDataById( "13", DateTime.Today, DateTime.Today.AddDays( 14 ) );
        return result;
    }

always returns null in "result". Can anyone spot开发者_StackOverflow中文版 why?

TIA,

David


In LINQ, execution of a query is usually deferred until the moment when you actually request the data. In your first approach you were only defining the query, but it was never executed; in your second approach it was, as soon as you you needed to enumerate the results.


I am not sure what the difference is, but we resolved this particular issue by using:

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

It's really puzzling to say the least...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜