Beispiel #1
0
        public void AddStudents(List <Student> students)
        {
            foreach (Student s in students)
            {
                context.Add <Student>(s);
            }

            context.SaveChanges();
        }
        public T Add(T itemToAdd)
        {
            var entity = dbContext.Add <T>(itemToAdd);

            dbContext.SaveChanges();
            return(entity.Entity);
        }
Beispiel #3
0
        public int AddStudent(Student newStudent)
        {
            _context.Add(newStudent);
            _context.SaveChanges();

            return(newStudent.IdStudent);
        }
Beispiel #4
0
 public void Add(Course course)
 {
     _ctx.Add(course);
     _ctx.SaveChanges();
 }
Beispiel #5
0
 public void Add(Course course)
 {
     _dbContext.Add(course);
     _dbContext.SaveChanges();
 }
        static void Main(string[] args)
        {
            List <string> studentNames = new List <string>()
            {
                "Giorgi", "Toby", "Michael", "Pam", "Dwight", "Jim"
            };

            List <string> subjectNames = new List <string>()
            {
                "Math", "Programming", "History", "Biology", "Chemistry"
            };

            using (var context = new UniversityDbContext())
            {
                for (int i = 0; i < 50; i++)
                {
                    context.Add(new Student
                    {
                        StudentName = studentNames.Random()
                    });
                }

                for (int i = 0; i < 5; i++)
                {
                    context.Add(new Subject
                    {
                        SubjectName = subjectNames[i]
                    });
                }

                context.SaveChanges();
            }

            using (var context = new UniversityDbContext())
            {
                var students = context.Students.AsEnumerable();

                var subjects = context.Subjects.AsEnumerable();

                foreach (var student in students)
                {
                    var randomSubject         = subjects.Random();
                    var distinctRandomSubject = subjects.Random();
                    while (randomSubject == distinctRandomSubject)
                    {
                        distinctRandomSubject = subjects.Random();
                    }

                    context.Add(new StudentSubject
                    {
                        StudentId = student.Id,
                        SubjectId = randomSubject.Id
                    });

                    context.Add(new StudentSubject
                    {
                        StudentId = student.Id,
                        SubjectId = distinctRandomSubject.Id
                    });
                }
                context.SaveChanges();
            }
            Console.WriteLine("The End!");
        }
Beispiel #7
0
 public void AddUser(User user)
 {
     _context.Add(user);
 }
Beispiel #8
0
 public void AddUser(User user)
 {
     _ctx.Add(user);
 }