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

烂漫一生 提交于 2019-12-10 02:48:54

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/11222694/the-method-skip-is-only-supported-for-sorted-input-in-linq-to-entities-the-me

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!