Пример #1
0
        // Query using a custom operation:
        // custom discount information for all products
        private IDataList QueryProductCustomDiscount()
        {
            // get OrderDetails table
            dynamic od = workspace.table(Utils.OrderDetails.Name);
            // aggregate OrderDetails table
            dynamic qp = workspace.query("query_productCustomDiscount", new
            {
                ds          = MyOp.ProgressiveDiscount(od.UnitPrice, od.Discount, od.Quantity), // calculate discount for a product in an order
                Product     = od.ProductID,                                                     // group by product
                OrderCount  = Op.Count(od.OrderID),                                             // order count for a product
                DiscountSum = Op.Sum("ds")                                                      // total progressive discount for a product in all orders
            });

            return(qp.Query.Execute());
        }
Пример #2
0
        // products within specified unit price range
        private IDataList QueryUnitPriceRange()
        {
            double from = (double)nudUnitPriceFrom.Value;
            double to   = (double)nudUnitPriceTo.Value;

            // get OrderDetails table
            dynamic od = workspace.table(Utils.OrderDetails.Name);
            // aggregate OrderDetails table
            dynamic qr = workspace.query("query_range", new
            {
                _range      = od.UnitPrice.Gte(from).Lte(to),    // narrow data to the specified unit price range
                ds          = Op.Mul(od.UnitPrice, od.Discount), // calculate the discount for a product in an order
                Price       = od.UnitPrice,                      // group by UnitPrice
                OrdersCount = Op.Count(od.OrderID),              // how many times products with the same price were ordered
                MaxDiscount = Op.Max("ds")                       // what is the maximum discount for products with the same price
            });

            return(qr.Query.Execute());
        }