Ejemplo n.º 1
0
        public void TestUniqueWithSave()
        {
            //new up the repository
            EntitiesRepository<Customer, NorthwindEntities> ctx =
                new EntitiesRepository<Customer, NorthwindEntities>(new NorthwindEntities());

            //new up a specification
            Specification<Customer> cust_spec =
                new Specification<Customer>(c => c.Country == "Germany" && c.CustomerID == "KOENE");

            var unique_german_cust = ctx.Unique("Customers", cust_spec);

            var rand_num = new Random(DateTime.Now.Year).Next();

            unique_german_cust.Orders.Add(new Order() { ShipName = "Nikovshi" + rand_num.ToString()  });

            ctx.Save();

            Assert.IsNotNull(unique_german_cust);

            Console.WriteLine("The Unique customer ID is : {0}", unique_german_cust.CustomerID);
        }
Ejemplo n.º 2
0
        public void Multi_Level_Mixed_Hierarchy_With_Persisting_Test()
        {
            EntitiesRepository<Customer, NorthwindEntities> repos =
                new EntitiesRepository<Customer, NorthwindEntities>(new NorthwindEntities());

            Specification<Customer> german_cust_spec =
                new Specification<Customer>(c => c.CustomerID == "ALFKI");

            var german_custs = repos.AllToIList(german_cust_spec, new
                                MultiLevelMixedStrategy());

            foreach (var cust in german_custs)
            {
                cust.Country = "Germany";
                Console.WriteLine("The Customer Name is {0}", cust.CompanyName);
                foreach (var order in cust.Orders)
                {
                    order.ShipName = "Battleship Potemkin";
                    Console.WriteLine("\tThe Order ID is : {0}", order.OrderID);
                    foreach (var orderline in order.Order_Details)
                    {
                        orderline.Discount = 0.15f;
                        Console.WriteLine("\t\tThe value ordered for Product ID {0} is {1}",
                            orderline.Product.ProductID, orderline.UnitPrice * orderline.Quantity);
                    }
                }
            }

            german_custs[0].Orders.Add(Order.CreateOrder(999999));
            repos.Save();
        }