Esempio n. 1
0
        public static void AddStudent()
        {
            using (var context = new EFExampleBasicContext())
            {
                var someClassId = context.Classes
                                  .Where(studyClass => studyClass.Name == "TA-81")
                                  .Select(studyClass => studyClass.Id)
                                  .FirstOrDefault();

                var newStudent = new Student()
                {
                    FirstName = "Anufriy",
                    LastName  = "Korch",
                    Address   = new Address()
                    {
                        City       = "Kiev",
                        FirstLine  = "Troeshina",
                        SecondLine = "Amin'"
                    },
                    StudyClassId = someClassId
                };

                context.Students.Add(newStudent);
                context.SaveChanges();
            }
        }
Esempio n. 2
0
        public static void ModifyStudent()
        {
            using (var context = new EFExampleBasicContext())
            {
                var firstStudent = context.Students.FirstOrDefault();

                firstStudent.FirstName = "modifiedName";

                var entry = context.Entry(firstStudent);

                context.SaveChanges();
            }
        }
Esempio n. 3
0
        public static void AddStudyClass()
        {
            using (var context = new EFExampleBasicContext()) {
                var newClass = new StudyClass()
                {
                    Name      = "TA-81",
                    StartYear = 2017,
                };

                context.Classes.Add(newClass);
                context.SaveChanges();
            }
        }