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
 private static void AddClasses(ClassDB ctx)
 {
     ctx.Classes.AddObject(new Class {
         Name = "Physics"
     });
     ctx.Classes.AddObject(new Class {
         Name = "Art"
     });
     ctx.Classes.AddObject(new Class {
         Name = "Music"
     });
 }
Example #5
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 #6
0
        private static void AddStudents(ClassDB ctx)
        {
            ctx.Students.AddObject(
                new Student
            {
                Name        = "Poonam",
                HomeAddress =
                {
                    Street = "Potomac",
                    City   = "Columbia",
                    State  = "MD"
                }
            });

            ctx.Students.AddObject(
                new Student
            {
                Name        = "Joy",
                HomeAddress =
                {
                    Street = "Oak",
                    City   = "Hagerstown",
                    State  = "MD"
                }
            });
            ctx.Students.AddObject(
                new Student
            {
                Name        = "Alex",
                HomeAddress =
                {
                    Street = "Main",
                    City   = "Hagerstown",
                    State  = "MD"
                }
            });
        }
Example #7
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();
        }