title: cast iqueryable
body: <p>how do i cast to cartItem?</p>
  
  <pre><code>              var newItem = from i in dc.CartItems
                                 where i.productID == item.productID
                                 select new {productID = i.productID,
                                             Quantity = i.Quantity + item.Quantity ,
                                             cartID = item.cartID };
  
              CartItem itemToUpdate = (here??)newItem;
              dc.CartItems.Attach(itemToUpdate, true);
  </code></pre>
  
  <p>next solution gives me this error ></p>
  
  <pre><code> List&lt;CartItem&gt; newItem = (from i in dc.CartItems
                                 where i.productID == item.productID
                                 select new {productID = i.productID,
                                             Quantity = i.Quantity + item.Quantity ,
                                             cartID = item.cartID }).Cast&lt;CartItem&gt;().ToList();
  
              CartItem itemToUpdate = newItem.First();
              dc.CartItems.Attach(itemToUpdate, true);
  </code></pre>
  
  <p>ERROR:No coercion operator is defined between types '&lt;>f__AnonymousType2`3[System.Int32,System.Int32,System.String]' and 'CartItem'.</p>
  
  <p>how about this code : this makes error too </p>
  
  <pre><code>            if (IfExist(item))
          {
              //if this product id in cart 
  
              // get the quantity  of existing cartItem
              int quantity  = (from i in dc.CartItems
                       where i.productID == item.productID
                       select i).First().Quantity;
  
              // sum quanitities of existing and just inserted item
  
              item.Quantity += quantity;
  
              dc.CartItems.Attach(item, true);
  </code></pre>
  
  <p>error : Cannot add an entity with a key that is already in use.</p>