Пример #1
0
        static void AddStudenten(StudentContext context)
        {
            if (context.Students.Count() == 0)
            {
                context.Add(new Student()
                {
                    Voornaam = "Bob", Achternaam = "Jansen", Leeftijd = 20, Geslacht = 'M'
                });
                context.Add(new Student()
                {
                    Voornaam = "Alice", Achternaam = "Smith", Leeftijd = 22, Geslacht = 'V'
                });
                context.Add(new Student()
                {
                    Voornaam = "Carl", Achternaam = "Johnson", Leeftijd = 23, Geslacht = 'M'
                });
                context.Add(new Student()
                {
                    Voornaam = "John", Achternaam = "Waters", Leeftijd = 19, Geslacht = 'M'
                });
                context.Add(new Student()
                {
                    Voornaam = "Will", Achternaam = "Anderson", Leeftijd = 23, Geslacht = 'M'
                });

                context.SaveChanges();
            }
        }
Пример #2
0
        static void AddInputStudenten(StudentContext context)
        {
            Console.Write("Wilt u records aanmaken?\n" +
                          "Typ Ja of Nee: ");
            string input = Console.ReadLine().ToLower();

            if (input == "ja")
            {
                Console.Write("Hoeveel records wilt u invullen?: ");
                int count = Int32.Parse(Console.ReadLine());

                for (int i = 0; i < count; i++)
                {
                    Console.Write("Student voornaam: ");
                    string voornaam = Console.ReadLine();

                    Console.Write("Student achternaam: ");
                    string achternaam = Console.ReadLine();

                    Console.Write("Student leeftijd: ");
                    int leeftijd = Int32.Parse(Console.ReadLine());

                    Console.Write("Student geslacht (1 character): ");
                    char geslacht = Console.ReadLine().ToCharArray()[0];

                    var student = new Student
                    {
                        Voornaam   = voornaam,
                        Achternaam = achternaam,
                        Leeftijd   = leeftijd,
                        Geslacht   = geslacht
                    };

                    context.Add(student);
                    context.SaveChanges();
                    Console.WriteLine();
                }
            }
        }