About the EF paging query error (Count must has a non-negative value.) Solution

Source: Internet
Author: User

The specific exception information is as follows, the first no write log only see error message: Count must has a non-negative Value, from the surface of the meaning can be seen that the count value appears negative, so error, check for a half-day reason also did not see why, until later, I put the LINQ expression out, found that skip (-10), I think the paging query will skip the previous page number of records according to the page number, So will skip, but here the number of skip is-10, this is for what, I think about whether it is the page number or the number of records per page has a problem, so I looked at the code, I found that there is no paging query pageindex and pagesize assignment, So pageindex default to 0.PageSize default is 10. So it will Skip (0-1) *10=-10 records, resulting in error, so the solution is very simple is to give pageindex and pagesize assignment, and sure enough after the changes are normal.

Expression:value (System.Data.Entity.Core.Objects.ObjectQuery ' 1[hidistro.efentities.storecollectioninfo]). Mergeas (appendonly). Where (A = True). Where (x = = (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 has a non-negative value.
Parameter name: Count
StackTrace: In System.Data.Entity.Core.Common.CommandTrees.ExpressionBuilder.DbExpressionBuilder.Skip ( dbexpressionbinding input, IEnumerable ' 1 sortOrder, dbexpression count)
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.OrderByLifter.OrderByLifterBase.ApplySortOrderToSkip ( DbExpression input, dbsortexpression sort, dbexpression k)
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.OrderByLifter.SortLifter.Skip (dbexpression k)
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.OrderByLifter.Skip (dbexpressionbinding input, DbExpression Skipcount)
At System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Skip (dbexpressionbinding input, dbexpression skipcount )
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SkipTranslator.TranslatePagingOperator (expressionconverter parent, dbexpression operand, dbexpression count)
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.PagingTranslator.TranslateUnary ( Expressionconverter parent, dbexpression operand, methodcallexpression call)
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate (expressionconverter parent, methodcallexpression Call)
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate (expressionconverter parent, methodcallexpression call, Sequencemethod Sequencemethod)
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate ( Expressionconverter parent, Methodcallexpression LINQ)
At System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator ' 1.Translate (expressionconverter Parent, Expression LINQ)
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression (Expression LINQ)
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.UnarySequenceMethodTranslator.Translate (expressionconverter parent, methodcallexpression Call)
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.SequenceMethodTranslator.Translate (expressionconverter parent, methodcallexpression call, Sequencemethod Sequencemethod)
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.MethodCallTranslator.TypedTranslate ( Expressionconverter parent, Methodcallexpression LINQ)
At System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TypedTranslator ' 1.Translate (expressionconverter Parent, Expression LINQ)
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.TranslateExpression (Expression LINQ)
In System.Data.Entity.Core.Objects.ELinq.ExpressionConverter.Convert ()
In System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan (Nullable ' 1 formergeoption)
In System.Data.Entity.Core.Objects.ObjectQuery ' 1.<>c__displayclass3.<getresults>b__2 ()
In System.data.entity.core.objects.objectcontext.executeintransaction[t] (func ' 1 func, Idbexecutionstrategy Executionstrategy, Boolean startlocaltransaction, Boolean releaseconnectiononsuccess)
In System.Data.Entity.Core.Objects.ObjectQuery ' 1.<>c__displayclass3.<getresults>b__1 ()
In System.data.entity.sqlserver.defaultsqlexecutionstrategy.execute[tresult] (Func ' 1 operation)
At System.Data.Entity.Core.Objects.ObjectQuery ' 1.GetResults (Nullable ' 1 formergeoption)
In System.Data.Entity.Core.Objects.ObjectQuery ' 1.<system.collections.generic.ienumerable<t>. Getenumerator>b__0 ()
In System.Data.Entity.Internal.LazyEnumerator ' 1.MoveNext ()
At System.Collections.Generic.List ' 1..ctor (IEnumerable ' 1 collection)
In System.linq.enumerable.tolist[tsource] (IEnumerable ' 1 source)
In Hidistro.ControlPanel.Depot.StoresHelper.GetStoreCollectionInfos (storecollectionsquery query) location g:\Hishop_kdt\ Branches\mec2.2\src\biz\controlpanel\depot\storeshelper.cs: Line No. 1422
Baseexception:count must has a non-negative value.
Parameter name: 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

About the EF paging query error (Count must has a non-negative value.) Solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.