title: Only primitive types do I need to cast?
body: <p>I am trying to use anonymous types in Entity Framework, but I am getting an error about</p>
  <blockquote>
  <p>Unable to create a constant value</p>
  </blockquote>
  <p><code>MinQty</code> and <code>MaxQty</code> are int so I don't know if I need to add to <code>Convert.ToInt32</code>?</p>
  <blockquote>
  <p>Unable to create a constant value of type 'Anonymous type'. Only primitive types or enumeration types are supported in this context.</p>
  </blockquote>
  <p>This builds a list object</p>
  <pre><code>var listOfLicense = (from l in db.License
      select new
      {
          l.ProductId,
          l.MinLicense,
          l.MaxLicense
      }).tolist();
  </code></pre>
  <p>This is the larger EF object where I am getting the error am I missing a casting?</p>
  <pre><code>var ShoppingCart = (from sc in db.ShoppingCarts
  Select new model.Shoppingchart{
     ShoppingCartId= sc.Id,
      MinQty = (int)listOfLicense 
          .Where(mt =&gt; (int)mt.ProductId == sc.ProductId)
          .Select(mt =&gt; (int)mt.MinLicense)
          .Min(mt =&gt; mt.Value),
      MaxQty = (int)listOfLicense 
          .Where(mt =&gt; (int)mt.ProductId == p.ProductId)
          .Select(mt =&gt;(int) mt.MaxQty)
          .Max(mt =&gt; mt.Value)}.tolist();
  </code></pre>