DeleteObject Method

ObjectContext.DeleteObject Method (Object)

 

Marks an object for deletion.

Namespace:   System.Data.Objects
Assembly:  System.Data.Entity (in System.Data.Entity.dll)

member DeleteObject : 
        entity:Object -> unit

Parameters

entity
Type: System.Object

An object that specifies the entity to delete. The object can be in any state except Detached.

Exception Condition
ArgumentNullException

entity is null.

InvalidOperationException

entity does not exist.

Marks an object for deletion from the ObjectStateManager. The object is deleted in the data source when the SaveChanges method is called.

Deleting the parent object also deletes all the child objects in the constrained relationship. This result is the same as enabling the CascadeDelete property on the association for the relationship.

The DeleteObject method can be called on objects that are already deleted.

These examples are based on the AdventureWorks Sales Model.

This example constructs an EntityKey with a specific ProductID, uses the key to retrieve a Product object from the data source, deletes the product, and saves the changes to the database.

No code example is currently available or this language may not be supported.

This example deletes an existing order item, adds a new item, and saves the changes to the database.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.5
Return to top
Show:
© 2016 Microsoft