使用 ADO.NET实体框架 删除时异常 “无法删除此对象,因为未在 ObjectStateManager 中找到它。”求解
在 System.Data.Objects.ObjectContext.DeleteObject(Object entity)
在 WMSDAL.VenderDAL.Del(Vender vender)
在 WMSBLL.VenderBLL.Del(Vender vender) 位置 D:\My Documents\VS_2008_PRO\Pro\WMS\WMSBLL\VenderBLL.cs:行号 43
在 WinForm.Model.VenderManagementControl.tbbtnDel_ItemClick(Object sender, ItemClickEventArgs e) 位置 D:\My Documents\VS_2008_PRO\Pro\WMS\WinForm\Model\VenderManagementControl.cs:行号 100
在 DevExpress.XtraBars.BarItem.OnClick(BarItemLink link)
在 DevExpress.XtraBars.BarBaseButtonItem.OnClick(BarItemLink link)
在 DevExpress.XtraBars.BarItemLink.OnLinkClick()
在 DevExpress.XtraBars.BarItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
在 DevExpress.XtraBars.BarButtonItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
在 DevExpress.XtraBars.BarItemLink.OnLinkActionCore(BarLinkAction action, Object actionArgs)
在 DevExpress.XtraBars.ViewInfo.BarSelectionInfo.ClickLink(BarItemLink link)
在 DevExpress.XtraBars.ViewInfo.BarSelectionInfo.UnPressLink(BarItemLink link)
在 DevExpress.XtraBars.Controls.CustomLinksControl.OnMouseUp(MouseEventArgs e)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 DevExpress.XtraBars.Controls.DockedBarControl.WndProc(Message& msg)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 WinForm.Program.Main() 位置 D:\My Documents\VS_2008_PRO\Pro\WMS\WinForm\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
在 System.Data.Objects.ObjectContext.DeleteObject(Object entity)
在 WMSDAL.VenderDAL.Del(Vender vender)
在 WMSBLL.VenderBLL.Del(Vender vender) 位置 D:\My Documents\VS_2008_PRO\Pro\WMS\WMSBLL\VenderBLL.cs:行号 43
在 WinForm.Model.VenderManagementControl.tbbtnDel_ItemClick(Object sender, ItemClickEventArgs e) 位置 D:\My Documents\VS_2008_PRO\Pro\WMS\WinForm\Model\VenderManagementControl.cs:行号 100
在 DevExpress.XtraBars.BarItem.OnClick(BarItemLink link)
在 DevExpress.XtraBars.BarBaseButtonItem.OnClick(BarItemLink link)
在 DevExpress.XtraBars.BarItemLink.OnLinkClick()
在 DevExpress.XtraBars.BarItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
在 DevExpress.XtraBars.BarButtonItemLink.OnLinkAction(BarLinkAction action, Object actionArgs)
在 DevExpress.XtraBars.BarItemLink.OnLinkActionCore(BarLinkAction action, Object actionArgs)
在 DevExpress.XtraBars.ViewInfo.BarSelectionInfo.ClickLink(BarItemLink link)
在 DevExpress.XtraBars.ViewInfo.BarSelectionInfo.UnPressLink(BarItemLink link)
在 DevExpress.XtraBars.Controls.CustomLinksControl.OnMouseUp(MouseEventArgs e)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 DevExpress.XtraBars.Controls.DockedBarControl.WndProc(Message& msg)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 WinForm.Program.Main() 位置 D:\My Documents\VS_2008_PRO\Pro\WMS\WinForm\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
主要是使用了不同的ObjectContext的原因
只要想法使用同个ObjectContext就可以了比如这样 点击查看
我个人认为是 只能使用一个context
写个静态的context变量,每次使用时都调用他,不要重新构造就可以 了