示例#1
0
        public object FacetsWithDocuments()
        {
            using (var session = DocumentStoreHolder.Store.OpenSession())
            {
                var facetResults = session
                                   .Query <Product, ProductsAndPriceAndSuplier>()
                                   .Where(x => x.UnitsInStock > 1)
                                   .ToFacets(MenuController.FixedFacet);

                return(DemoUtilities.FormatRangeResults(facetResults.Results));
            }
        }
示例#2
0
        public object DynamicAggregation(string fromVal = "0", string toVal = "999")
        {
            var from = int.Parse(fromVal);
            var to   = int.Parse(toVal);

            using (var session = DocumentStoreHolder.Store.OpenSession())
            {
                var result = session.Query <Product, Products>()
                             .Where(x => x.UnitsInStock >= from && x.UnitsInStock <= to)
                             .AggregateBy(x => x.Category)
                             .SumOn(x => x.UnitsInStock)
                             .ToList();

                return(DemoUtilities.FormatRangeResults(result.Results));
            }
        }
示例#3
0
        public object FacetsDynamicRange(string fromVal = "10", string toVal = "20")
        {
            var from = decimal.Parse(fromVal);
            var to   = decimal.Parse(toVal);

            List <Facet> newFacet = new List <Facet>()
            {
                new Facet
                {
                    Name = "Products"
                },
                new Facet <Product>
                {
                    Name   = x => x.PricePerUnit,
                    Ranges =
                    {
                        x => x.PricePerUnit < from,
                        x => x.PricePerUnit >= from && x.PricePerUnit < to,
                        x => x.PricePerUnit >= to,
                    }
                },
                new Facet <Product>
                {
                    Name   = x => x.UnitsInStock,
                    Ranges =
                    {
                        x => x.UnitsInStock < 10,
                        x => x.UnitsInStock >= 10
                    }
                }
            };

            using (var session = DocumentStoreHolder.Store.OpenSession())
            {
                var facetResults = session
                                   .Query <Product, ProductsAndPriceAndSuplier>()
                                   .Where(x => x.UnitsInStock > 1)
                                   .ToFacets(newFacet);

                return(DemoUtilities.FormatRangeResults(facetResults.Results));
            }
        }