I am trying to delete a whole row of data from a table. The code I’m using is:
OModel.Cart pncart = database.Carts.FirstOrDefault(
pn => pn.OrderId == Session["OOID"] &&
pn.PartNumber == Request.QueryString["PartNumber"]);
database.Carts.DeleteObject(pncart);
database.SaveChanges();
And the error it gives me, is:
LINQ to Entities does not recognize the method ‘System.Object
get_Item(System.String)’ method, and this method cannot be translated
into a store expression. Description: An unhandled exception
occurred during the execution of the current web request. Please
review the stack trace for more information about the error and where
it originated in the code.Exception Details: System.NotSupportedException: LINQ to Entities
does not recognize the method ‘System.Object get_Item(System.String)’
method, and this method cannot be translated into a store expression.
It says something about NotSupportException, so I’m guessing you just can’t do it this way.
So, how would I go about deleting from the table? I thought this was the correct way.
I would declare variables for the
Session["OOID"]andRequest.QueryString["PartNumber"]instead of using them within your linq expression.I believe it is telling you that it cannot translate those operations.