title: Linq: A query inside a field
body: <p>I want to write a nested query.</p>
  
  <p>I have 3 objects:</p>
  
  <pre><code>public class Invoice
  {
    public int Id { get; set; }
    public ICollection&lt;InvoiceDet&gt; Details { get; set; }
  }
  public class InvoiceDet
  {
    public int InvoiceId { get; set; }
    public int Quantity { get; set; }
    public int ArticleId { get; set; }
  }
  
  public class Article
  {
    public int Id { get; set; }
    public string Description { get; set; }
    public decimal Price { get; set; }
  }
  </code></pre>
  
  <p>Now I want to create the linq query as follows, but it throws an error:
  "Linq To Entities exception does not recognize the method and cannot be translated into store expression"</p>
  
  <pre><code>var model = from i in db.Invoices
              select new
              {
                 Id = i.Id,
                 details = (from d in i.Details
                            from a in db.Articles.Where(a =&gt; a.Id == d.ArticleId)
                                             select new 
                                             {
                                                 Id = a.Id,
                                                 Description = a.Description,
                                                 Total = a.Price * d.Quantity
                                             }).Distinct().ToList()
             };
  </code></pre>
  
  <p>Any help will be appreciated. Thanks a lot!</p>