Want to build the ChatGPT based Apps? Start here
Become a member
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
C# Corner Home
Technologies
Monthly Leaders
ASK A QUESTION
Forum guidelines
Abhilash J A
815
2.4k
550.1k
how to take first 10 record using LINQ ?
Apr 21 2017 6:02 AM
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 ?
Reply
Answers (
4
)
find the occurance of characters in a string using c#
How to be a C# developer??