只有LINQ to Entities中的排序输入才支持“Skip”方法。必须在方法“跳过”之前调用“OrderBy”方法 [英] The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'

查看:1216
本文介绍了只有LINQ to Entities中的排序输入才支持“Skip”方法。必须在方法“跳过”之前调用“OrderBy”方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



$ p
$ b $ p

$ p
$ b $ p $ b

  DefaultModel.RegisterContext(typeof(masterEntities1),new ContextConfiguration(){ScaffoldAllTables = true}); 

当我运行一个应用程序,它显示一个表的列表,但是当我点击任何一个表抛出异常:



仅在LINQ to Entities中排序输入支持跳过方法。必须在方法跳过之前调用OrderBy方法。



但是我没有在我的应用程序中声明任何查询。

解决方案

如果您使用的话,您必须调用 .OrderBy' .Skip 方法。例如,如果您使用类似于以下内容:



results = results.Skip(pageNumber * size).Take(size);



在上述情况下,您以前必须使用 .OrderBy 订单该查询是否正在计划使用分页方法或类似的东西。如果您有一个 Id 字段,请将其添加到原始查询表达式中,以消除错误:



.OrderBy(x => x.Id);


I am working on a Dynamic data.

after creating a dynamic model and registering in global.asax, like

DefaultModel.RegisterContext(typeof(masterEntities1),new ContextConfiguration() { ScaffoldAllTables = true }); 

when i run an application, it shows a list of tables but when i click any of the table it throws an exception:

The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.

but i haven't declare any query into my application.

解决方案

You must call .OrderBy' on your query if you use the .Skip method. For example if you were using something similar to the following:

results = results.Skip(pageNumber * size).Take(size);

In the case above you would have previously had to use the .OrderBy to order the query if you are planning on using paging methods or something of the like. If you have an Id field, adding this onto your original query expression should eliminate the error:

.OrderBy(x => x.Id);

这篇关于只有LINQ to Entities中的排序输入才支持“Skip”方法。必须在方法“跳过”之前调用“OrderBy”方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆