public void TestOrderByTranslation() { DocumentClient client = TestCommon.CreateClient(true); IOrderedQueryable <Family> families = new DocumentQuery <Family>(client, ResourceType.Document, typeof(Document), "//dbs/", null); // Ascending IQueryable query = from f in families where f.Int == 5 && f.NullableInt != null orderby f.IsRegistered select f.FamilyId; this.VerifyQueryTranslation(query.ToString(), "SELECT VALUE root[\"id\"] FROM root WHERE ((root[\"Int\"] = 5) AND (root[\"NullableInt\"] != null)) ORDER BY root[\"IsRegistered\"] ASC "); query = families.Where(f => f.Int == 5 && f.NullableInt != null).OrderBy(f => f.IsRegistered).Select(f => f.FamilyId); this.VerifyQueryTranslation(query.ToString(), "SELECT VALUE root[\"id\"] FROM root WHERE ((root[\"Int\"] = 5) AND (root[\"NullableInt\"] != null)) ORDER BY root[\"IsRegistered\"] ASC "); query = from f in families orderby f.FamilyId select f; this.VerifyQueryTranslation(query.ToString(), "SELECT * FROM root ORDER BY root[\"id\"] ASC "); query = families.OrderBy(f => f.FamilyId); this.VerifyQueryTranslation(query.ToString(), "SELECT * FROM root ORDER BY root[\"id\"] ASC "); query = from f in families orderby f.FamilyId select f.FamilyId; this.VerifyQueryTranslation(query.ToString(), "SELECT VALUE root[\"id\"] FROM root ORDER BY root[\"id\"] ASC "); query = families.OrderBy(f => f.FamilyId).Select(f => f.FamilyId); this.VerifyQueryTranslation(query.ToString(), "SELECT VALUE root[\"id\"] FROM root ORDER BY root[\"id\"] ASC "); // Descending query = from f in families where f.Int == 5 && f.NullableInt != null orderby f.IsRegistered descending select f.FamilyId; this.VerifyQueryTranslation(query.ToString(), "SELECT VALUE root[\"id\"] FROM root WHERE ((root[\"Int\"] = 5) AND (root[\"NullableInt\"] != null)) ORDER BY root[\"IsRegistered\"] DESC "); query = families.Where(f => f.Int == 5 && f.NullableInt != null).OrderByDescending(f => f.IsRegistered).Select(f => f.FamilyId); this.VerifyQueryTranslation(query.ToString(), "SELECT VALUE root[\"id\"] FROM root WHERE ((root[\"Int\"] = 5) AND (root[\"NullableInt\"] != null)) ORDER BY root[\"IsRegistered\"] DESC "); query = from f in families orderby f.FamilyId descending select f; this.VerifyQueryTranslation(query.ToString(), "SELECT * FROM root ORDER BY root[\"id\"] DESC "); query = families.OrderByDescending(f => f.FamilyId); this.VerifyQueryTranslation(query.ToString(), "SELECT * FROM root ORDER BY root[\"id\"] DESC "); query = from f in families orderby f.FamilyId descending select f.FamilyId; this.VerifyQueryTranslation(query.ToString(), "SELECT VALUE root[\"id\"] FROM root ORDER BY root[\"id\"] DESC "); query = families.OrderByDescending(f => f.FamilyId).Select(f => f.FamilyId); this.VerifyQueryTranslation(query.ToString(), "SELECT VALUE root[\"id\"] FROM root ORDER BY root[\"id\"] DESC "); // orderby multiple expression is not supported yet query = from f in families orderby f.FamilyId, f.Int select f.FamilyId; try { query.ToString(); } catch (Exception e) { Assert.IsTrue(e.Message.Contains("Method 'ThenBy' is not supported.")); } }