Ejemplo n.º 1
0
        static void TestClientOrder()
        {
            using (ClientOrderContext context = new ClientOrderContext())
            {
                ClientModel c = new ClientModel()
                {
                    Name  = "Customer 1",
                    Email = "Email"
                };

                OrderModel o1 = new OrderModel()
                {
                    Value  = 200,
                    Client = c
                };
                OrderModel o2 = new OrderModel()
                {
                    Value  = 300,
                    Client = c
                };
                c.Orders.Add(o1);
                c.Orders.Add(o2);

                context.Clients.Add(c);
                context.Orders.Add(o1);
                context.Orders.Add(o2);
                context.SaveChanges();
                var items = context.Clients;
                foreach (var x in items)
                {
                    Console.WriteLine("Client : {0}, {1}, {2}",
                                      x.ClientId, x.Name, x.Email);
                    foreach (var ox in x.Orders)
                    {
                        Console.WriteLine("\tOrders: {0}, {1}",
                                          ox.OrderId, ox.Value.ToString());
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void CanAddAndUpdateSomeData()
        {
            var client = new Client {
                LastName = "Julie", FirstName = "Julie"
            };

            using (var context = new ClientOrderContext(_options))
            {
                context.Add(client);
                context.SaveChanges();
            }
            client.FirstName += "t";
            using (var context = new ClientOrderContext(_options))
            {
                context.Clients.Update(client);
                context.SaveChanges();
            }
            using (var context = new ClientOrderContext(_options))
            {
                Assert.AreEqual("Juliet", context.Clients.FirstOrDefault().FirstName);
            }
        }
Ejemplo n.º 3
0
 protected void CascadeDelete <TEntity>(TEntity entity) where TEntity : ClientChangeTracker
 {
     Context.Entry(entity).State = EntityState.Deleted; //TRACKING
     Context.SaveChanges();
 }