Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 394
Abhishek gupta Avatar asked Jun 27 '12 08:06

Abhishek gupta


1 Answers

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

like image 127
atconway Avatar answered Oct 15 '22 14:10

atconway