Rediger

Del via


ObjectContext.Dispose Method

Definition

Releases the resources used by the object context.

Overloads

Dispose()

Releases the resources used by the object context.

Dispose(Boolean)

Releases the resources used by the object context.

Dispose()

Releases the resources used by the object context.

public:
 virtual void Dispose();
public void Dispose ();
abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit
Public Sub Dispose ()

Implements

Remarks

This method closes the connection if it was opened by the Entity Framework. After Dispose is called, operations that require an open connection, such as executing a query or calling the ToTraceString method, will cause an exception. Operations that do not require an open connection, such as composing a query or attaching objects, will not cause an exception. The Dispose method does not close any explicitly opened connections.

Limiting the scope of an ObjectContext within a using block (Using in Visual Basic) ensures that resources are correctly disposed. For more information, see Managing Connections and Transactions.

The Dispose() method calls the virtual (Overridable in Visual Basic) Dispose(Boolean) method.

See also

Applies to

Dispose(Boolean)

Releases the resources used by the object context.

protected:
 virtual void Dispose(bool disposing);
protected virtual void Dispose (bool disposing);
abstract member Dispose : bool -> unit
override this.Dispose : bool -> unit
Protected Overridable Sub Dispose (disposing As Boolean)

Parameters

disposing
Boolean

true to release both managed and unmanaged resources; false to release only unmanaged resources.

Remarks

This method closes the connection. After Dispose is called, operations that require an open connection, such as executing a query or calling the ToTraceString method, will cause an exception. Operations that do not require an open connection, such as composing a query or attaching objects, will not cause an exception.

Limiting the scope of an ObjectContext within a using block (Using in Visual Basic) ensures that resources are properly disposed. For more information, see Managing Connections and Transactions.

See also

Applies to