2

I'm using Simple.Data to select data from a table and am wondering if there is a way to select the top 10 records from the table.

Something like:

var result = _database.UserList.All()
            .Select(_database.UserList.Name).Take(10)  -- or .Top(10)
Dave
  • 3,812
  • 5
  • 31
  • 39

1 Answers1

2

Something exactly like:

var result = _database.UserList.All()
             .Select(_database.UserList.Name).Take(10);

More info on Take and Skip in this blog post: http://blog.markrendle.net/simple-data-0-8-0-and-more/

While we're here, it's worth mentioning that if you just want those names as strings, you can do this:

var result = _database.UserList.All()
             .Select(_database.UserList.Name)
             .Take(10)
             .ToScalarList<string>();
Mark Rendle
  • 9,274
  • 1
  • 32
  • 58
  • mmm OK don't know why it wasn't working, but I just added a distinct and where clause and I'm now getting: Incorrect syntax near the keyword 'distinct'. – Dave Jan 21 '13 at 23:00
  • To fix the incorrect syntax error I just needed to move the distinct before the select, but I don't know why! – Dave Jan 22 '13 at 20:27
  • 1
    Your link is dead @Mark Rendle, the article is now at http://blog.markrendle.net/simple-data-0-8-0-and-more/ – RyanfaeScotland Mar 23 '15 at 15:31