title: Entity Framework query to custom object Class with List
body: <p>I am using entity frame work for Web API 2.0 I am trying to query Author Book to a custom Object.</p>
  
  <p>Object is :</p>
  
  <pre><code>public class AuthorBooks
  {
      public Author Author;
      public List&lt;BookDetail&gt; BookDetails;
  
      public AuthorBooks() {
          Author = new Author();
          BookDetails = new List&lt;BookDetail&gt;();
      }
  }
  
  public class BookDetail
  {
      public BookDetail()
      {
          Book = new Book();
          Category = new Category();
          SubCategory = new SubCategory();
  
      }
  
      public Book Book { get; set; }
      public Category Category { get; set; }
      public SubCategory SubCategory { get; set; }
  
  
  }
  </code></pre>
  
  <p>Here Book, Author, Category and SubCategory are entities</p>
  
  <p>Relation presently working properly is:
  Author
  ----List</p>
  
  <pre><code>public class AuthorBooks
  {
      public Author Author;
      public List&lt;Book&gt; Book;
  
      public AuthorBooks() {
          Author = new Author();
          Book = new List&lt;Book&gt;();
      }
  }
  </code></pre>
  
  <p>using query I get proper result : </p>
  
  <pre><code>AuthorBooks authorBooks = (from a in _context.Authors.Where(author =&gt; author.Id == id)
                                     join b in _context.Books on a.Id equals b.AuthorName into b1
  
                                     select new AuthorBooks { Author = a, Book = b1.ToList()  }).Single&lt;AuthorBooks&gt;();
  </code></pre>
  
  <p>But Now for Above Mentioned Relation : 
    Author
  ---List</p>
  
  <p>where Book Detail of other Entities related by Id's of Entities Category and SubCategory.</p>
  
  <p>So How Can It be Done with BookDetails Id???</p>
  
  <pre><code> AuthorBooks authorBooks = (from a in _context.Authors.Where(author =&gt; author.Id == id)
                                     join b in _context.Books on a.Id equals b.AuthorName into b1
                                     from b2 in b1
                                     join c in _context.Categories on b2.CategoryId equals c.Id
                                     join s in _context.SubCategories on b2.SubCategoryId equals s.Id                                    
                                     select new AuthorBooks { Author = a, BookDetails = #####List&lt;BookDetail&gt;#######  }).Single&lt;AuthorBooks&gt;();
  </code></pre>