public void Run() { var testLimit = 1000000; var pubs = GetPublishers().Take(testLimit); _c.AddRange(pubs); _c.SaveChanges(); var authors = GetAuthors().Take(testLimit); _c.AddRange(authors); _c.SaveChanges(); IEnumerable <Subject> subjects = GetSubjects().Take(testLimit); _c.AddRange(subjects); _c.SaveChanges(); SeedCategories(); pubs = _c.Query <Publisher>().ToList(); authors = _c.Query <Author>().ToList(); subjects = _c.Query <Subject>().ToList(); var cats = _c.Query <Category>().ToList(); IEnumerable <Book> books = GetBooks(pubs, authors, cats, subjects).Take(testLimit); foreach (var b in books) { try { _c.Add(b); _c.SaveChanges(); } catch (DbEntityValidationException e) { _log.Error("Could not save book {0}, reason: {1}", b.Title, e.Message); foreach (var eve in e.EntityValidationErrors) { _log.Error("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", eve.Entry.Entity.GetType().Name, eve.Entry.State); foreach (var ve in eve.ValidationErrors) { _log.Error("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } _c.LocalClear <Book>(); } catch (Exception ex) { _log.Error("Could not save book {0}, reason: {1}", b.Title, ex.Message); } } }
public ActionResult Create([Bind(Include = "BookID,Title,AlternativeTitle,AuthorID,CategoryID,PublisherID,InitialPrintedYear,ActualPrintYear,Language,Material,Read,Pages,ISBN,Website,CoverLink,Rating,CodeWithinSerie,Condition,ReviewNote,Location")] Book book) { if (ModelState.IsValid) { _db.Add(book); _db.SaveChanges(); return(RedirectToAction("Index")); } PopulateCategoryDropDownList(book.CategoryID); PopulatePublishersDropDownList(book.PublisherID); return(View(book)); }