/// <summary> /// Create a new AuthorBook object. /// </summary> /// <param name="bookId">Initial value of the BookId property.</param> /// <param name="authorId">Initial value of the AuthorId property.</param> /// <param name="isPrimary">Initial value of the IsPrimary property.</param> public static AuthorBook CreateAuthorBook(global::System.Int32 bookId, global::System.Int32 authorId, global::System.Boolean isPrimary) { AuthorBook authorBook = new AuthorBook(); authorBook.BookId = bookId; authorBook.AuthorId = authorId; authorBook.IsPrimary = isPrimary; return(authorBook); }
static void RunExample() { using (var context = new EFRecipesEntities()) { var b1 = new Book { ISBN = "978-1-847193-81-0", Title = "jQuery Reference Guide" }; var b2 = new Book { ISBN = "978-1-29298333", Title = "jQuery Tips and Tricks" }; var b3 = new Book { ISBN = "978-1033988429", Title = "Silverlight 2" }; var a1 = new Author { Name = "Jonathan Chaffer" }; var a2 = new Author { Name = "Chad Campbell" }; var ab1 = new AuthorBook { Author = a1, Book = b1, IsPrimary = true }; var ab2 = new AuthorBook { Author = a1, Book = b2, IsPrimary = false }; var ab3 = new AuthorBook { Author = a2, Book = b3, IsPrimary = false }; context.AuthorBooks.AddObject(ab1); context.AuthorBooks.AddObject(ab2); context.AuthorBooks.AddObject(ab3); context.SaveChanges(); } using (var context = new EFRecipesEntities()) { context.ContextOptions.LazyLoadingEnabled = true; Console.WriteLine("Authors and Their Books..."); foreach (var author in context.Authors) { Console.WriteLine("{0}", author.Name); foreach (var book in author.Books) { Console.WriteLine("\t{0}, ISBN = {1}", book.Title, book.ISBN); } } } Console.WriteLine("Press <enter> to continue..."); Console.ReadLine(); }
/// <summary> /// Deprecated Method for adding a new object to the AuthorBooks EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToAuthorBooks(AuthorBook authorBook) { base.AddObject("AuthorBooks", authorBook); }