NopCommerce EF problems
I am using nopcommerce for my web shop and I am using Tasks that are getting information from an external system when an order has been shipped. When it is shipped I want to capture the payment and then set it as shipped. However, I keep getting EF errors. Any way to get around this for now? I need to have it up and running
An entity object cannot be referenced by multiple instances of IEntityChangeTracker.
See my code below:
int orderId = PBSManager.GetOrderIdByCustomOrderNumber(customOrderNumber);
NopObjectContext db = ObjectContextHelper.CurrentObjectContext;
Order order = db.Orders.SingleOrDefault(c => c.OrderId == orderId);
//Incorrect or开发者_高级运维der id
if (order == null)
{
//Skip this one if we cannot find the id
continue;
}
if (OrderManager.CanCapture(order))
{
string error = string.Empty;
OrderManager.Capture(order, ref error);
if (!string.IsNullOrEmpty(error))
{
PBSManager.HandleCaptureError(order, error);
return;
}
}
if (OrderManager.CanShip(order))
{
OrderManager.Ship(order.OrderId, true);
}
I am just guessing that probably you are creating another context in the OrderManager class. You should use the same context.
Can this link be of any help
Multiple instances of context
Doesn't nopCommerce store the current context in the HttpContext, have you tried looking for it in there?
精彩评论