Ejemplo n.º 1
0
 /// <summary>
 /// Заполнить таблицу Toys
 /// </summary>
 /// <param name="model"></param>
 private static void AddDataIntoToys(MyModel1 model)
 {
     model.Toys.Add(new Toys()
     {
         Toy_Id   = 1,
         Child_Id = 3,
         Toy_Name = "Мяч",
         Color    = "Красный"
     });
     model.Toys.Add(new Toys()
     {
         Toy_Id   = 2,
         Child_Id = 1,
         Toy_Name = "Слон",
         Color    = "Оранжевый"
     });
     model.Toys.Add(new Toys()
     {
         Toy_Id   = 3,
         Child_Id = 2,
         Toy_Name = "Каракатица",
         Color    = "Розовый"
     });
     model.Toys.Add(new Toys()
     {
         Toy_Id   = 4,
         Child_Id = 3,
         Toy_Name = "Попугай",
         Color    = "Зеленый"
     });
 }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            MyModel1 model = new MyModel1();

            Database.SetInitializer(new DropCreateDatabaseAlways <MyModel1>());
            // Заполняем таблички
            AddDataIntoChildren(model);
            AddDataIntoToys(model);
            model.SaveChanges();


            var childNames = model.Toys.Include(x => x.Children).ToList();

            PrintItems(childNames.Select(x => x.Toy_Name).ToList());
            var children = model.Children.Find(3);

            Console.WriteLine($"Found child: {children.Child_Name}");
            Console.ReadLine();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Заполнить таблицу Children
 /// </summary>
 /// <param name="model"></param>
 private static void AddDataIntoChildren(MyModel1 model)
 {
     model.Children.Add(new Children()
     {
         Child_Id   = 1,
         Child_Name = "Максим",
         Child_Age  = 9
     });
     model.Children.Add(new Children()
     {
         Child_Id   = 2,
         Child_Name = "Аня",
         Child_Age  = 5
     });
     model.Children.Add(new Children()
     {
         Child_Id   = 3,
         Child_Name = "Толик",
         Child_Age  = 3
     });
 }