Example #1
0
        private static void DeleteStudentsFromPhysics(ClassDB ctx)
        {
            var physics = ctx.Classes.First(c => c.Name == "Physics");

            physics.Students.Clear();
            ctx.SaveChanges();
        }
Example #2
0
        private static void DeleteStudentsFromClasses(ClassDB ctx)
        {
            var students = ctx.Students.ToList();

            foreach (var student in students)
            {
                ctx.DeleteObject(student);
            }
            ctx.SaveChanges();
        }
Example #3
0
        private static void DeleteClasses(ClassDB ctx)
        {
            var classes = ctx.Classes.ToList();

            foreach (var @class in classes)
            {
                ctx.DeleteObject(@class);
            }
            ctx.SaveChanges();
        }
Example #4
0
        static void Main(string[] args)
        {
            var ctx = new ClassDB();

            AddStudents(ctx);
            AddClasses(ctx);
            ctx.SaveChanges();

            AssociateStudentsWithClasses(ctx);

            DeleteClasses(ctx);
            DeleteStudentsFromPhysics(ctx);
            DeleteStudentsFromClasses(ctx);
        }
Example #5
0
        private static void AssociateStudentsWithClasses(ClassDB ctx)
        {
            var students = ctx.Students.ToList();
            var physics  = ctx.Classes.First(c => c.Name == "Physics");

            foreach (var student in students)
            {
                physics.Students.Add(student);
            }

            var music = ctx.Classes.First(c => c.Name == "Music");

            foreach (var student in students.Take(2))
            {
                music.Students.Add(student);
            }

            var art = ctx.Classes.First(c => c.Name == "Art");

            art.Students.Add(students.First());


            ctx.SaveChanges();
        }