Exemplo n.º 1
0
        public void Run(string[] args)
        {
            using (var session = store.OpenSession())
            {
                var product = new Product
                    {
                        Cost = 3.99m,
                        Name = "Milk"
                    };

                session.Store(product);
                session.SaveChanges();

                session.Store(new Order
                    {
                        Customer = "customer/ayende",
                        OrderLines =
                            {
                                new OrderLine
                                    {
                                        ProductId = product.Id,
                                        Quantity = 3
                                    },
                            }
                    });
                session.SaveChanges();
            }
        }
Exemplo n.º 2
0
        private static void PrintFirst20Products()
        {
            var rand = new Random();
            var orderedBag = new OrderedBag<Product>((pr, pr1) => pr.Price.CompareTo(pr1.Price));
            var start = DateTime.Now;
            for (int i = 0; i < 500000; i++)
            {
                var product = new Product
                {
                    Name = "Product" + (i + 1),
                    Price = rand.Next(1000, 50000)
                };

                orderedBag.Add(product);
            }

            for (int i = 0; i < 10000; i++)
            {
                var initialPrice = rand.Next(1000, 50000);
                var products = orderedBag.Range(new Product { Price = initialPrice }, true, new Product { Price = initialPrice + 20000 }, true).Take(20).ToList();
                foreach (var prod in products)
                {
                    Console.WriteLine("{0}->{1}", prod.Name, prod.Price);
                }
            }
            Console.WriteLine(DateTime.Now - start);
        }