Note that there are some explanatory texts on larger screens.

plurals
  1. POEntity Framework Error
    primarykey
    data
    text
    <p>I have a little problem. I am encountering the following error each time I try update my entityset.</p> <blockquote> <p>Unable to update the EntitySet 'ShoppingCart' because it has a DefiningQuery and no InsertFunction element exists in the ModificationFunctionMapping element to support the current operation.</p> </blockquote> <p>The code is: `</p> <pre><code>public void AddItem(string cartID, string productID, string quantity) { using (CommerceEntities db = new CommerceEntities()) { try { var myItem = (from c in db.ShoppingCarts where c.CartID == cartID &amp;&amp; c.ProductID == productID select c).FirstOrDefault(); if (myItem == null) { ShoppingCart cartadd = new ShoppingCart(); cartadd.CartID = cartID; cartadd.Quantity = quantity; cartadd.ProductID = productID; cartadd.DateCreated = DateTime.Now; db.ShoppingCarts.AddObject(cartadd); } else { myItem.Quantity += Convert.ToInt32(quantity); } db.SaveChanges(); } catch (Exception exp) { throw new Exception("ERROR: Unable to Add Item to Cart - " +exp.Message); } } } </code></pre> <p>`</p> <p>Please help me. I can provide more information if required, I am new to this Entity Framework Model and following the tutorial on <a href="http://www.asp.net/web-forms/tutorials/tailspin-spyworks/tailspin-spyworks-part-5" rel="nofollow">This page</a>.</p> <p>Update: I added primary keys and redesigned the whole database. Now the error changed to:</p> <blockquote> <p>System.Data.UpdateException was unhandled by user code Message=An error occurred while updating the entries. See the inner exception for details.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload