Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
4
Reply
how to take first 10 record using LINQ ?
Mani Kandan
Apr 21 2017 6:02 AM
393
Reply
Hello,
If there is have more than 10 records, then take only 10,
var query = from a
in
context.Advertisements where a.idPartner == partnerid select a;
count = query.Count();
if
(count > 10)
return
(query.Skip(startIndex).Take(10).ToList());
else
return
query.ToList();
now the error occured,
The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.
Then I have tried, this code:
return
(query.OrderBy(p=>p.idAdvertisement).Skip(startIndex).Take(10).ToList());
But here occurred another error,
Incorrect syntax near 'OFFSET'.
Invalid usage of the option NEXT in the FETCH statement.
How can I solve this ?
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
4
)
Next Recommended Forum
find the occurance of characters in a string using c#
How to be a C# developer??