Search code examples
simple.data

Simple.data select top N records


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)

Solution

  • 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>();