Removes the object from the object context.
Assembly: System.Data.Entity (in System.Data.Entity.dll)
Removes the object from the ObjectStateManager. This disables change tracking and identity resolution for that object. For more information, see Attaching and Detaching Objects (Entity Framework).
After the method is called, the system will no longer keep references that point to this object and it can be collected by the garbage collector.
Garbage collection can only occur if the user code does not have any references to the detached object.
The following considerations apply when detaching objects:
only affects the specific object that is passed to the method. If the object being detached has related objects in the object context, those objects are not detached.
Detaching objects does not affect data in the data source.
Cascade delete directives and referential constraints are not enforced during a detach operation.
For more information, see Attaching and Detaching Objects (Entity Framework).
' This method is called to detach SalesOrderHeader objects and ' related SalesOrderDetail objects from the supplied object ' context when no longer needed by the application. ' Once detached, the resources can be garbage collected. Private Shared Sub DetachOrders(ByVal context As ObjectContext, ByVal order As SalesOrderHeader) Try ' Detach each item from the collection. While order.SalesOrderDetails.Count > 0 ' Detach the first SalesOrderDetail in the collection. context.Detach(order.SalesOrderDetails.First()) End While ' Detach the order. context.Detach(order) Catch ex As InvalidOperationException Console.WriteLine(ex.ToString()) End Try End Sub
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.