title: Return Original datatype after LINQ group by
body: <p>I need my LINQ Query to return the Product Datatype, after being grouped. It seems to be encased into an anonymous psuedo family.</p>
  
  <p>I have some properties in Product that I don't care about, just needing the p.ID and p.Name etc.</p>
  
  <p>The error I'm getting at the moment with this is:</p>
  
  <pre><code>The entity or complex type 'DatabaseModel.Product' cannot be constructed in a LINQ to Entities query.
  </code></pre>
  
  <p>This is my Method:</p>
  
  <pre><code>        public static List&lt;Product&gt; GetSellableSpecialOffers(DatabaseEntities db)
      {
  
          var query = from p in db.Products
                      where (p.Visible == true &amp;&amp; p.Active == true)
                      &amp;&amp; p.ShowInSpecialOffers == true
                      group p by p.FamilyID == null ? 0 : p.FamilyID into f
                      select new Product {
                      ID = f.First().ID,
                      Name = f.First().Name,
                      Cost = f.First().Cost,
                      RRP = f.First().RRP
                      };
  
          return query.ToList();
      }
  </code></pre>
  
  <p>What is the problem? Is there a better way around this? SQL would always return 1 record instead of encasing the object in a secondary datatype, I don't get it.</p>
  
  <p>Many thanks,</p>
  
  <p><strong>EDIT 1:</strong></p>
  
  <p>My apologies for extending the specification, but I need the returned product to be programatically generated e.g.</p>
  
  <pre><code>select new Product {
                      ID = f.First().ID,
                      Name = f.First().Name,
                      Cost = f.OrderBy(p =&gt; p.NowCost).FirstOrDefault(),
                      RRP = f.First().RRP
                      }
  </code></pre>
  
  <p><em>or</em> if I could strongly type the family class:</p>
  
  <pre><code>    public partial class ProductFamily
  {
      public Product GroupedProduct 
      {
          get
          {
              return this.Products.OrderBy(p =&gt; p.NowCost).FirstOrDefault();
          }
      }
  }
  </code></pre>
  
  <p>Then I would do:</p>
  
  <pre><code> var query = (from p in db.Products
                      where (p.Visible == true &amp;&amp; p.Active == true)
                      &amp;&amp; p.ShowInSpecialOffers == true
                      group p by p.ProductFamily == null ? null : p.ProductFamily into f
                       select f.GroupedProduct).ToList&lt;Product&gt;();
  </code></pre>
  
  <p>But I can't get either solution to work with what I have.</p>