public static void Seed(DbContext context) { //Bekleyen migrationsları direk migrate eder. // context.Database.Migrate(); //Yada bekleyen migrations yoksa.. //if (context.Database.GetAppliedMigrations().Count().Equals(0)) //{ //} if (context is CourseContext) { //Eğer Bu contexte ait tabloları beslemek istiyorsak. //Dependency Injection.. CourseContext _context = context as CourseContext; if (_context.Courses.Count().Equals(0)) { _context.Instructor.AddRange(MyInstructors); _context.Courses.AddRange(Courses); _context.SaveChanges(); } } if (context is UserContext) { UserContext _dbUsers = context as UserContext; if (_dbUsers.Users.Count().Equals(0)) { _dbUsers.AddRange(Users); _dbUsers.SaveChanges(); } } }
public void CreateCourse(Course newCourse) { _db.Courses.Add(newCourse); _db.SaveChanges(); }