首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

linq 时间有关问题

2012-08-16 
linq 时间问题[codeC#]varinfofromgiindb.GoodInfosJoinodindb.OrderDetailsesongi.GoodIDequalsod.Good

linq 时间问题
[code=C#]
var   info   =   from   gi   in   db.GoodInfos
                      Join   od   in   db.OrderDetailses   on   gi.GoodID   equals   od.GoodID   into   odJoin
                        from   a   in   odJoin.DefaultIfEmpty()
                        where   DateTime.Now.CompareTo(gi.InstoreTime)   >   180
                                                      select   new
                                                      {
                                                              gi.ReceiveTime,
                                                              gi.GoodID,
                                                              gi.GoodName,
                                                              gi.Location,
                                                              gi.BarCode,
                                                              gi.InstoreTime,
                                                              gi.GoodState,
                                                              a.IsOutScan

                                                      };

                                info   =   info.Where(id   =>   id.GoodState   ==   32   &&   id.IsOutScan   ==   0);

                                info   =   info.OrderBy(id   =>   id.GoodID);


                                var   resaultDate   =   info.Skip((PageIndex   -   1)   *   RowsCount).Take(RowsCount).ToList();


[/code]

为什么在运行到var   resaultDate   =   info.Skip((PageIndex   -   1)   *   RowsCount).Take(RowsCount).ToList();
时会报错:“无法将类型“System.Nullable`1”强制转换为类型“System.Object”。LINQ   to   Entities   仅支持强制转换   Entity   Data   Model   基元类型。”



[解决办法]
info.Skip((PageIndex - 1) * RowsCount).Take(RowsCount)这句查出来的数据正常吗?
[解决办法]
LINQ to Entities 有专门的函数进行比较,System.Data.Objects.EntityFunctions下

System.Data.Objects.EntityFunctions.DiffMinutes(DateTime.Now,gi.InstoreTime) < 0

热点排行