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); }
public int AddStudent(Student newStudent) { _context.Add(newStudent); _context.SaveChanges(); return(newStudent.IdStudent); }
public void Add(Course course) { _ctx.Add(course); _ctx.SaveChanges(); }
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!"); }
public void AddUser(User user) { _context.Add(user); }
public void AddUser(User user) { _ctx.Add(user); }