Sk Asraf Sk Asraf - 5 months ago 14
SQL Question

how can take row number 10 to 20 over 100+ rows using entity framework

i have a table with 100+ rows ,i want to row number 10 to 20 using entity frame work ,but i can't understand how to write the code

my code is

db.Products.Where(p => p.Name == "product").Take(10, 20).ToList());


but it showing error

Answer

Use .Skip() and Take()

db.Products.Where(p => p.Name == "product").Skip(10).Take(10).ToList();

^Also the error is Extra ) at the end.

Note *(Suggested by Tim Schmelter & MatBailie) : Order your resultset before paging the rows to avoid arbitrary and unpredictable output.

Comments