{"action":"created","issue":{"url":"https://api.github.com/repos/mbdavid/LiteDB/issues/139","repository_url":"https://api.github.com/repos/mbdavid/LiteDB","labels_url":"https://api.github.com/repos/mbdavid/LiteDB/issues/139/labels{/name}","comments_url":"https://api.github.com/repos/mbdavid/LiteDB/issues/139/comments","events_url":"https://api.github.com/repos/mbdavid/LiteDB/issues/139/events","html_url":"https://github.com/mbdavid/LiteDB/issues/139","id":138840869,"number":139,"title":"Order By","user":{"login":"Siegmar","id":5322318,"avatar_url":"https://avatars.githubusercontent.com/u/5322318?v=3","gravatar_id":"","url":"https://api.github.com/users/Siegmar","html_url":"https://github.com/Siegmar","followers_url":"https://api.github.com/users/Siegmar/followers","following_url":"https://api.github.com/users/Siegmar/following{/other_user}","gists_url":"https://api.github.com/users/Siegmar/gists{/gist_id}","starred_url":"https://api.github.com/users/Siegmar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Siegmar/subscriptions","organizations_url":"https://api.github.com/users/Siegmar/orgs","repos_url":"https://api.github.com/users/Siegmar/repos","events_url":"https://api.github.com/users/Siegmar/events{/privacy}","received_events_url":"https://api.github.com/users/Siegmar/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-03-06T21:29:49Z","updated_at":"2016-03-07T01:00:15Z","closed_at":"2016-03-07T01:00:15Z","body":"Hi,\r\nConsidering the Code Project article about LINQ, OrderBy should be used like this:\r\n\r\n```cs\r\n// WHERE\r\nalbumEnumerable = albumCollection\r\n    .Include(x => x.Artist)\r\n    //.Find(x => x.AlbumId > albumId, skip , limit);\r\n    .Find(x => x.AlbumId > albumId);\r\n// ORDER BY\r\nalbumEnumerable = albumEnumerable\r\n    .OrderByDescending(x => x.Title)\r\n    .Skip(skip)\r\n    .Take(limit);\r\n```\r\nConsider I have 1.000 Albums and keep 900 after filtering.\r\nIf I execute the C# code above I get 900 in my IEnumerable, consuming a lot of memory.\r\nJust after loading all 900 I order them and filter the first 3.\r\n\r\nBut if I execute the SQL shown below in Entity Framework or NHIbernate I load just 3 records in memory:\r\n\r\n```sql\r\nSELECT TOP 3 *\r\nFROM Album\r\nWHERE Album > 20\r\nORDER BY Title DESC\r\n```\r\n\r\nIs there any way to ordering the Collection, before filtering, instead of ordering the IEnumerable ?\r\n"},"comment":{"url":"https://api.github.com/repos/mbdavid/LiteDB/issues/comments/193027342","html_url":"https://github.com/mbdavid/LiteDB/issues/139#issuecomment-193027342","issue_url":"https://api.github.com/repos/mbdavid/LiteDB/issues/139","id":193027342,"user":{"login":"Siegmar","id":5322318,"avatar_url":"https://avatars.githubusercontent.com/u/5322318?v=3","gravatar_id":"","url":"https://api.github.com/users/Siegmar","html_url":"https://github.com/Siegmar","followers_url":"https://api.github.com/users/Siegmar/followers","following_url":"https://api.github.com/users/Siegmar/following{/other_user}","gists_url":"https://api.github.com/users/Siegmar/gists{/gist_id}","starred_url":"https://api.github.com/users/Siegmar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Siegmar/subscriptions","organizations_url":"https://api.github.com/users/Siegmar/orgs","repos_url":"https://api.github.com/users/Siegmar/repos","events_url":"https://api.github.com/users/Siegmar/events{/privacy}","received_events_url":"https://api.github.com/users/Siegmar/received_events","type":"User","site_admin":false},"created_at":"2016-03-07T01:00:15Z","updated_at":"2016-03-07T01:00:15Z","body":"Hi,\r\nThanks for the answer.\r\nAnyway I may use the solution above or the solution below:\r\n\r\n```cs\r\nExpression<Func<Album, bool>> where = System.Linq.Dynamic.DynamicExpression.ParseLambda<Album, bool>(\"AlbumId > @0\", albumId);\r\nalbumQueryable = albumCollection\r\n    .Include(x => x.Artist)\r\n    .Find(where)\r\n    .AsQueryable();\r\nalbumEnumerable = albumQueryable\r\n    .OrderBy(\"Title descending\")\r\n    .Skip(skip)\r\n    .Take(limit)\r\n```"}}