private BookDTO Map(Book dbBook) { return new BookDTO() { Id = dbBook.Id, Title = dbBook.Title, Author = dbBook.Author != null ? new AuthorDTO() { Id = dbBook.Author.Id, Name = dbBook.Author.Name }:null, Isbn = dbBook.Isbn }; }
//convert books to bookDTO private BookDTO Map(Book dbBook) { return new BookDTO() { Id = dbBook.Id, Title = dbBook.Title, //so there will not be a null reference exception Author = dbBook.Author != null ? //dbBook has an author new AuthorDTO() { Id = dbBook.Author.Id, Name = dbBook.Author.Name } : //dbBook does NOT have an author null, Isbn = dbBook.Isbn }; }