星空网 > 软件开发 > ASP.net

关于EF分页查询报错(Count must have a non

具体的异常信息如下,一开始没有写日志只看到错误信息:Count must have a non-negative value.,从表面意思可以看出来是Count值出现了负数,所以报错,查了半天的原因也没有看出来为什么,直到后面,我把Linq表达式输了出来,发现Skip(-10),我一想分页查询会根据页码跳过前面页码的记录数,所以会用Skip来跳过,但是这里的Skip数量为-10,这是为什么呢,我想了一下会不会是页码或者每页记录数有问题,于是我看了一下代码,果然发现没有给分页查询的PageIndex和PageSize赋值,所以PageIndex默认为0.PageSize默认为10.所以就会跳过(0-1)*10=-10条记录,导致报错,所以解决办法很简单了就是给PageIndex和PageSize赋值,果然修改之后一切正常。

Expression:value(System.Data.Entity.Core.Objects.ObjectQuery`1[Hidistro.EFEntities.StoreCollectionInfo]).MergeAs(AppendOnly).Where(a => True).Where(x => (Convert(x.StoreId) == value(Hidistro.ControlPanel.Depot.StoresHelper+<>c__DisplayClass3c).query.StoreId)).Where(x => (x.StoreId == value(Hidistro.ControlPanel.Depot.StoresHelper+<>c__DisplayClass3c).query.StoreId.Value)).Where(item => True).OrderByDescending(item => item.PayTime).Skip(-10).Take(10)
ErrorMessage:Count must have a non-negative value.
参数名: count
StackTrace: 在 System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder.DbExpressionBuilder.Skip(DbExpressionBinding input, IEnumerable`1 sortOrder, DbExpression count)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.OrderByLifter.OrderByLifterBase.ApplySortOrderToSkip(DbExpression input, DbSortExpression sort, DbExpression k)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.OrderByLifter.SortLifter.Skip(DbExpression k)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.OrderByLifter.Skip(DbExpressionBinding input, DbExpression skipCount)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Skip(DbExpressionBinding input, DbExpression skipCount)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SkipTranslator.TranslatePagingOperator(ExpressionConverter parent, DbExpression operand, DbExpression count)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.PagingTranslator.TranslateUnary(ExpressionConverter parent, DbExpression operand, MethodCallExpression call)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate(ExpressionConverter parent, MethodCallExpression call, SequenceMethod sequenceMethod)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate(ExpressionConverter parent, MethodCallExpression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator`1.Translate(ExpressionConverter parent, Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression(Expression linq)
在 System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert()
在 System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
在 System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass3.<GetResults>b__2()
在 System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
在 System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass3.<GetResults>b__1()
在 System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
在 System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
在 System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
在 System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
在 System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
在 System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
在 Hidistro.ControlPanel.Depot.StoresHelper.GetStoreCollectionInfos(StoreCollectionsQuery query) 位置 g:\Hishop_kdt\branches\MEC2.2\src\Biz\ControlPanel\Depot\StoresHelper.cs:行号 1422
BaseException:Count must have a non-negative value.
参数名: count
TargetSite:System.Data.Entity.Core.Common.CommandTrees.DbSkipExpression Skip(System.Data.Entity.Core.Common.CommandTrees.DbExpressionBinding, System.Collections.Generic.IEnumerable`1[System.Data.Entity.Core.Common.CommandTrees.DbSortClause], System.Data.Entity.Core.Common.CommandTrees.DbExpression)
ExSource:EntityFramework




原标题:关于EF分页查询报错(Count must have a non

关键词:分页

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

tiktok澳大利亚小店:https://www.goluckyvip.com/tag/84088.html
tiktok国际版老版本:https://www.goluckyvip.com/tag/84089.html
批量折扣:https://www.goluckyvip.com/tag/8409.html
开通英国tiktok:https://www.goluckyvip.com/tag/84090.html
海外国际版tiktok:https://www.goluckyvip.com/tag/84091.html
tiktok澳洲小店:https://www.goluckyvip.com/tag/84092.html
海南琼海市有什么旅游景点 琼海市的旅游景点:https://www.vstour.cn/a/362187.html
快手本地生活上线“吃喝免费试”活动 强化低价供给心智 :https://www.kjdsnews.com/a/1836309.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流