public void HavingWithSimpleExpression() { OrderItemCollection coll = new OrderItemCollection(); coll.es.Connection.Name = "ForeignKeyTest"; OrderItemQuery q = new OrderItemQuery(); //q.es2.Connection.Name = "ForeignKeyTest"; q.Select(q.OrderID, q.Quantity.Sum().As("TotalQty")); q.Where(q.Discount.IsNull()); q.GroupBy(q.OrderID); switch (coll.es.Connection.ProviderSignature.DataProviderName) { case "EntitySpaces.SqlServerCeProvider": case "EntitySpaces.SqlServerCe4Provider": case "EntitySpaces.VistaDBProvider": case "EntitySpaces.VistaDB4Provider": q.Having(q.Quantity.Sum() > 100); q.OrderBy("<TotalQty>", esOrderByDirection.Descending); break; case "EntitySpaces.SQLiteProvider": q.Having((q.Quantity * 1).Sum() > 100); q.OrderBy(q.Quantity.Sum().Descending); break; default: q.Having(q.Quantity.Sum() > 100); q.OrderBy(q.Quantity.Sum().Descending); break; } Assert.IsTrue(coll.Load(q), "Load"); Assert.AreEqual(3, coll.Count, "Count"); int qty = Convert.ToInt32(coll[0].GetColumn("TotalQty")); Assert.AreEqual(240, qty, "GetColumn"); }
public void HavingWithComplexExpression() { OrderItemCollection coll = new OrderItemCollection(); coll.es.Connection.Name = "ForeignKeyTest"; OrderItemQuery q = new OrderItemQuery(); q.Select(q.OrderID, (q.Quantity * q.UnitPrice).Sum().As("TotalPrice")); q.Where(q.Discount.IsNull()); q.GroupBy(q.OrderID); q.Having((q.Quantity * q.UnitPrice).Sum() > 500); switch (coll.es.Connection.ProviderSignature.DataProviderName) { case "EntitySpaces.SqlServerCeProvider": case "EntitySpaces.SqlServerCe4Provider": case "EntitySpaces.VistaDBProvider": case "EntitySpaces.VistaDB4Provider": q.OrderBy("<TotalPrice>", esOrderByDirection.Descending); break; default: q.OrderBy((q.Quantity * q.UnitPrice).Sum().Descending); break; } Assert.IsTrue(coll.Load(q), "Load"); Assert.AreEqual(2, coll.Count, "Count"); decimal price = Convert.ToDecimal(coll[0].GetColumn("TotalPrice")); Assert.AreEqual(1940.0M, price, "GetColumn"); }