コード例 #1
0
        public Product GetNearest(string productName, double lat, double lon, int skip = 0, int take = 10)
        {
            var result = _client.Cypher.Match("(p:Product)-[r: ContainedIn]->(s:Shop)")
                         .Where <ORMProduct>(p => p.Name == productName)
                         .Return((p, s, r) => new
            {
                Product = p.As <ORMProduct>(),
                Cont    = r.As <ORMContainedIn>(),
                Shop    = s.As <ORMShop>(),
                Dist    = Return.As <double>("distance(point({ latitude: toFloat(s.Latitude), longitude: toFloat(s.Longitude)}),point({ latitude: " +
                                             lat + ", longitude: " + lon + "}))")
            }).OrderBy("Dist").Skip(skip).Limit(take).Results;

            ORMProduct pr      = result.First().Product;
            Product    product = new Product()
            {
                Id    = pr.Id,
                Name  = pr.Name,
                Shops = new Dictionary <Shop, ContainedIn>()
            };

            foreach (var res in result)
            {
                product.Shops.Add(res.Shop.ToShop(), res.Cont.ToContainedIn());
            }

            return(product);
        }
コード例 #2
0
        public Product GetCheapestInCity(string productName, string cityName, int skip, int take)
        {
            var result = _client.Cypher.Match("(p:Product)-[r:ContainedIn]->(s:Shop)-[l:LocatedAt]->(c:City)")
                         .Where <ORMProduct>(p => p.Name == productName)
                         .AndWhere <ORMCity>(c => c.Name == cityName)
                         .Return((p, r, s) => new
            {
                Product = p.As <ORMProduct>(),
                Cont    = r.As <ORMContainedIn>(),
                Shop    = s.As <ORMShop>()
            }).OrderBy("Cont.Price").Skip(skip).Limit(take).Results;

            ORMProduct pr      = result.First().Product;
            Product    product = new Product()
            {
                Id    = pr.Id,
                Name  = pr.Name,
                Shops = new Dictionary <Shop, ContainedIn>()
            };

            foreach (var res in result)
            {
                product.Shops.Add(res.Shop.ToShop(), res.Cont.ToContainedIn());
            }

            return(product);
        }
コード例 #3
0
 public static Product ToProduct(this ORMProduct ormProduct)
 {
     return(new Product()
     {
         Id = ormProduct.Id,
         Measure = ormProduct.Measure,
         Name = ormProduct.Name
     });
 }
コード例 #4
0
        public bool Insert(Product entity)
        {
            ORMProduct product = entity.ToORMProduct();

            _client.Cypher
            .Merge("(p:Product {product})")
            .WithParam("product", product)
            .ExecuteWithoutResults();
            return(true);
        }
コード例 #5
0
        private Product GetByCriteria(Expression <Func <ORMProduct, bool> > criteria)
        {
            var result = _client.Cypher.Match("(p:Product)-[r:ContainedIn]->(s:Shop)")
                         .Where(criteria)
                         .Return((p, r, s) => new
            {
                Products = p.CollectAs <ORMProduct>(),
                Cont     = r.CollectAs <ORMContainedIn>(),
                Shops    = s.CollectAs <ORMShop>()
            }).Results.FirstOrDefault();

            ORMProduct pr = result.Products.FirstOrDefault();

            return(FillDalProduct(pr, result.Shops.ToList(), result.Cont.ToList()));
        }
コード例 #6
0
        //public Dictionary<Shop, double> GetOpt(string productName1, string productName2, string cityName)
        //{
        //    var result = _client.Cypher.Match($"(p1:Product {{Name: \"{productName1}\"}})-[l:ContainedIn]->(s:Shop)<-[r:ContainedIn]-(p2:Product {{Name: \"{productName2}\"}}), (c:City {{Name:\"{cityName}\"}})")
        //        .Where("(s)-[:LocatedAt]->(c)")
        //        .Return((s, l, r) => new
        //        {
        //            Shop = s.As<Shop>(),
        //            Sum = Return.As<double>("l.Price + r.Price")

        //        }).OrderBy("Sum").Results;

        //    Dictionary<Shop, double> dict = new Dictionary<Shop, double>();
        //    foreach (var res in result)
        //    {
        //        dict.Add(res.Shop.ToShop(), res.Sum);
        //    }

        //    return dict;
        //}

        private Product FillDalProduct(ORMProduct pr, List <ORMShop> shops, List <ORMContainedIn> links)
        {
            Product product = new Product()
            {
                Id      = pr.Id,
                Measure = pr.Measure,
                Name    = pr.Name
            };

            for (int i = 0; i < links.Count; i++)
            {
                product.Shops.Add(shops[i].ToShop(), links[i].ToContainedIn());
            }

            return(product);
        }