Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Quote:
table users contains 1000 records with ID 1-1000 and i need to retrieve only from id 200 to 500 records


What I have tried:

List<string> users = ((from tbl in helper.GetTables<TBL_Users>()
                                where tbl.aaaa == true && tbl.bbbb != true
                                 orderby tbl.Id descending
                                 select new {
                                           tbl.email,
                                      }).Skip(start).Take(end - start);
Posted
Updated 26-Feb-20 0:39am

In a short:

C#
var emails = your_data
    .Where(x=> x.aaaa==true && tbl.bbbb==false)
    .OrderByDescending(x=>x.Id)
    .Skip(199)
    .Take(301)
    .Select(x=>x.email)
    .ToList();


Above query skips 199 records and gets 301 records to get a range of 200-500.
Note: it does NOT mean that you will get ids from 200 to 500!
 
Share this answer
 
v2
You can try
C#
List<string> emails = (from user in helper.GetTables<TBL_Users>()
                      where user.aaaa && !user.bbbb
                         && user.Id >= 200 && user.Id <= 500
                      orderby user.Id descending
                      select user.email
                      ).ToList();
 
Share this answer
 
v2
Comments
Arfat M 26-Feb-20 6:53am    
Cannot implicitly convert type 'System.Collections.Generic.List<anonymoustype#1>' to 'System.Collections.Generic.List<string>'
phil.o 26-Feb-20 6:55am    
Solution revised.
Maciej Los 26-Feb-20 11:07am    
I believe you're right.
5ed!
phil.o 26-Feb-20 11:29am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900