private static Book AddBook(string title, string description, DateTime datePublished, int pages, string isbn, int bookCopies) { using (BookDBDataContext context = new BookDBDataContext()) { Book newBook = new Book() { Title = title, BookResume = description, DatePublished = datePublished, Pages = pages, ISBN = isbn }; context.Books.InsertOnSubmit(newBook); while (bookCopies > 0) { var bookCopy = new BookCopy() { Book = newBook }; context.BookCopies.InsertOnSubmit(bookCopy); bookCopies--; } //var existing = context.Authors.FirstOrDefault(a => a.FirstName.Contains("G")); //if (existing != null) //{ // var bookAuthor = new BookAuthor() // { // BookID = newBook.ID, // AuthorID = existing.ID // }; //} //var bookGenre = new BookGenre() //{ // BookID = newBook.ID //}; context.SubmitChanges(); return newBook; } }
partial void DeleteBookCopy(BookCopy instance);
partial void UpdateBookCopy(BookCopy instance);
partial void InsertBookCopy(BookCopy instance);
private void detach_BookCopies(BookCopy entity) { this.SendPropertyChanging(); entity.Book = null; }
private void attach_BookCopies(BookCopy entity) { this.SendPropertyChanging(); entity.Book = this; }