Exemplo n.º 1
0
        public void TestFetchingStrateyAllIlist()
        {
            //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");

            MakePreferedFetchingStrategy stratey = new MakePreferedFetchingStrategy();

            var list = ctx.AllToIList(stratey);

            Assert.IsTrue(list.ToList().Count > 0);
        }
Exemplo 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();
        }
Exemplo n.º 3
0
        public void Multi_Level_Mixed_Hierarchy_Test()
        {
            EntitiesRepository<Customer, NorthwindEntities> repos =
                new EntitiesRepository<Customer, NorthwindEntities>(new NorthwindEntities());

            var custs = repos.AllToIList(new MultiLevelMixedStrategy());

            foreach (var cust in custs)
            {
                Console.WriteLine("The Customer Name is {0}", cust.CompanyName);
                foreach (var order in cust.Orders)
                {
                    Console.WriteLine("\tThe Order ID is : {0}", order.OrderID);
                    foreach (var orderline in order.Order_Details)
                    {
                        Console.WriteLine("\t\tThe value ordered for Product ID {0} is {1}",
                            orderline.Product.ProductID, orderline.UnitPrice * orderline.Quantity);
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void Fetching_Lazy_EntityReference_Eager_EntityCollection()
        {
            EntitiesRepository<Order, NorthwindEntities> repos =
                new EntitiesRepository<Order, NorthwindEntities>(new NorthwindEntities());

            Specification<Order> italian_spec =
                new Specification<Order>(o => o.Customer.Country == "Italy");

            var italian_orders = repos.AllToIList(new LazyEntityReferenceEagerEntityCollection());

            foreach (var order in italian_orders)
            {
                Console.WriteLine("The Customer Name is {0}", order.Customer.CompanyName);
                foreach (var orderLine in order.Order_Details)
                {
                    Console.WriteLine("\tThe value ordered for Product ID {0} is {1}",
                        orderLine.ProductID, orderLine.UnitPrice * orderLine.Quantity);
                }
            }
        }
Exemplo n.º 5
0
        public void Fetching_Eager_EntityReference_Lazy_EntityCollection()
        {
            EntitiesRepository<Order, NorthwindEntities> repos =
                new EntitiesRepository<Order, NorthwindEntities>(new NorthwindEntities());

            var orders = repos.AllToIList(new EagerEntityReferenceLazyEntityCollection());

            foreach (var order in orders)
            {
                //customer is eager
                Console.WriteLine("The Customer Name is {0}", order.Customer.CompanyName);
                foreach (var orderLine in order.Order_Details)
                {
                    //order details is lazy
                    Console.WriteLine("\tThe value ordered for Product ID {0} is {1}",
                        orderLine.ProductID, orderLine.UnitPrice * orderLine.Quantity);
                }
            }
        }
Exemplo n.º 6
0
        public void Example_Role_Specified_Strategy_Test()
        {
            EntitiesRepository<Customer, NorthwindEntities> repos =
                new EntitiesRepository<Customer, NorthwindEntities>(new NorthwindEntities());

            var custs = repos.AllToIList<ICustomerMakePrefered>();

            foreach (var cust in custs)
            {
                Console.WriteLine("The Customer Name is {0}", cust.CompanyName);
                foreach (var order in cust.Orders)
                {
                    Console.WriteLine("\tThe Order ID is : {0}", order.OrderID);
                    foreach (var orderline in order.Order_Details)
                    {
                        Console.WriteLine("\t\tThe value ordered for Product ID {0} is {1}",
                            orderline.Product.ProductID, orderline.UnitPrice * orderline.Quantity);
                    }
                }
            }
        }