示例#1
0
        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;
            }
        }
示例#2
0
 partial void DeleteBookCopy(BookCopy instance);
示例#3
0
 partial void UpdateBookCopy(BookCopy instance);
示例#4
0
 partial void InsertBookCopy(BookCopy instance);
示例#5
0
		private void detach_BookCopies(BookCopy entity)
		{
			this.SendPropertyChanging();
			entity.Book = null;
		}
示例#6
0
		private void attach_BookCopies(BookCopy entity)
		{
			this.SendPropertyChanging();
			entity.Book = this;
		}