public void Reseed(DogTrainingDataContext context) { // Add default Views while initializing database if (context.Views.Count() == 0) { context.Views.AddOrUpdate(m => m.Id, new View() { Id = (int)ViewEnum.Index, Name = Enum.GetName(typeof(ViewEnum), ViewEnum.Index) }, new View() { Id = (int)ViewEnum.AboutFoundation, Name = Enum.GetName(typeof(ViewEnum), ViewEnum.AboutFoundation) }, new View() { Id = (int)ViewEnum.AboutSchool, Name = Enum.GetName(typeof(ViewEnum), ViewEnum.AboutSchool) }, new View() { Id = (int)ViewEnum.Contact, Name = Enum.GetName(typeof(ViewEnum), ViewEnum.Contact) }, new View() { Id = (int)ViewEnum.Courses, Name = Enum.GetName(typeof(ViewEnum), ViewEnum.Courses) }, new View() { Id = (int)ViewEnum.Donate, Name = Enum.GetName(typeof(ViewEnum), ViewEnum.Donate) }, new View() { Id = (int)ViewEnum.News, Name = Enum.GetName(typeof(ViewEnum), ViewEnum.News) }); context.SaveChanges(); } if (context.Images.Count() == 0) { context.Images.AddOrUpdate(m => m.Id, new Image() { Id = 1, Path = "Content/Images/Slider/Index/dess1.jpg", ViewId = (int)ViewEnum.Index }, new Image() { Id = 1, Path = "Content/Images/Slider/Index/dess2.jpg", ViewId = (int)ViewEnum.Index }, new Image() { Id = 1, Path = "Content/Images/Slider/Index/dess3.jpg", ViewId = (int)ViewEnum.Index }, new Image() { Id = 1, Path = "Content/Images/Slider/Index/dess4.jpg", ViewId = (int)ViewEnum.Index }, new Image() { Id = 1, Path = "Content/Images/Slider/Index/nela1.jpg", ViewId = (int)ViewEnum.Index }, new Image() { Id = 1, Path = "Content/Images/Slider/Index/dess5.jpg", ViewId = (int)ViewEnum.Index }, new Image() { Id = 1, Path = "Content/Images/Slider/Index/nela2.jpg", ViewId = (int)ViewEnum.Index }); context.SaveChanges(); } }
public DatabaseInitializer() { Database.SetInitializer(new DropCreateDatabaseIfModelChanges<DogTrainingDataContext>()); if (!IsInitialized) { using (DogTrainingDataContext context = new DogTrainingDataContext()) { context.Database.Initialize(false); Reseed(context); IsInitialized = true; } } }