I had a requirement to only ever retrieve a maximum of 100 items no matter the query. In SQL this is easy and can be achieved using the SELECT TOP (N).. syntax.
Using a lambda expression to return a collection of IQueryable objects can be achieved simply as the following:
IQueryable<MyObject> resultSet =Remember here that the actual REST call is not made until you call ToList() on the collection. This query simply creates the REST URL as a string.
service.MyObjects.Where(c => c.Name.Contains(searchText))
.OrderBy(x => x.Name)
.Take(100);
But using the extension method Take(n) will translate to TOP in SQL.
2 comments:
Thank you Simon
John Poblete
piggybacksoft@comcast.net
Tanks friend!!
Post a Comment