Example #1
0
        static void Main(string[] args)
        {
            using (var ctx = new StudentContext())
            {
                var stud = new Student()
                {
                    StudentName = "Bill"
                };

                ctx.Students.Add(stud);
                ctx.SaveChanges();
            }
        }
        static void Main(string[] args)
        {
            using (var db = new StudentContext())
            {
                var student1 = new Student()
                {
                    StudentName = "Penelope"
                };
                var student2 = new Student()
                {
                    StudentName = "Erin"
                };
                var student3 = new Student()
                {
                    StudentName = "Jane"
                };

                var subject1 = new Subject()
                {
                    SubjectName = "Mathematics"
                };
                var subject2 = new Subject()
                {
                    SubjectName = "Science"
                };
                var subject3 = new Subject()
                {
                    SubjectName = "Art History"
                };

                student1.StudentSubjects.Add(subject1);
                student2.StudentSubjects.Add(subject2);
                student3.StudentSubjects.Add(subject3);

                db.Students.Add(student1);
                db.Students.Add(student2);
                db.Students.Add(student3);

                db.SaveChanges();
            }
        }