NopCommerce EF 问题
我正在为我的网上商店使用 nopcommerce,并且正在使用在订单发货后从外部系统获取信息的任务。当发货时,我想捕获付款,然后将其设置为已发货。但是,我不断收到 EF 错误。目前有什么办法可以解决这个问题吗?我需要启动并运行它
一个实体对象不能被 IEntityChangeTracker 的多个实例引用。
请参阅下面的我的代码:
int orderId = PBSManager.GetOrderIdByCustomOrderNumber(customOrderNumber);
NopObjectContext db = ObjectContextHelper.CurrentObjectContext;
Order order = db.Orders.SingleOrDefault(c => c.OrderId == orderId);
//Incorrect order 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 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 order 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只是猜测您可能正在 OrderManager 类中创建另一个上下文。您应该使用相同的上下文。
此链接是否有任何帮助
上下文的多个实例
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
nopCommerce 是否没有将当前上下文存储在 HttpContext 中,您是否尝试在其中查找它?
Doesn't nopCommerce store the current context in the HttpContext, have you tried looking for it in there?