コード例 #1
0
        static void TryOneToManyContext()
        {
            using (var context = new OneToManyContext())
            {
                Customer customer1 = new Customer()
                {
                    City = "Iasi",
                    Name = "Marian"
                };

                Order order1 = new Order()
                {
                    Date       = DateTime.Now,
                    TotalValue = 27.9m,
                    Customer   = customer1
                };

                Order order2 = new Order()
                {
                    Date       = DateTime.Now,
                    TotalValue = 99.9m,
                    Customer   = customer1
                };

                context.Customers.Add(customer1);
                context.Orders.Add(order1);
                context.Orders.Add(order2);
                context.SaveChanges();

                foreach (var customer in context.Customers)
                {
                    Console.WriteLine($"Name: {customer.Name} City: {customer.City}");

                    foreach (var order in customer.Orders)
                    {
                        Console.WriteLine($"Date: {order.Date}, Value: {order.TotalValue}");
                    }
                }
            }
        }
コード例 #2
0
 public GradesController(OneToManyContext context)
 {
     _context = context;
 }
コード例 #3
0
 public StudentsController(OneToManyContext context)
 {
     _context = context;
 }