// when we know the exact bookID and authorID we use this method static void AddBookAuthorPair(int bookID, int authorID) { using (BookDatabaseDataContext connection = new BookDatabaseDataContext()) { connection.AddBookAuthorRecord(bookID, authorID); } }
// gets the last added book/author pair and adds their IDs to the BookAuthor table static void AddBookAuthorPair() { int bookIDToAdd, authorIDToAdd; using (BookDatabaseDataContext connection = new BookDatabaseDataContext()) { var listOfBookIDs = from book in connection.Books select book.BookID; var listOfAuthorIDs = from author in connection.Authors select author.AuthorID; bookIDToAdd = listOfBookIDs.Max(); authorIDToAdd = listOfAuthorIDs.Max(); connection.AddBookAuthorRecord(bookIDToAdd, authorIDToAdd); } }