ObjectContext::DeleteObject Method (Object^)
Marks an object for deletion.
Assembly: System.Data.Entity (in System.Data.Entity.dll)
| 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.
This example deletes an existing order item, adds a new item, and saves the changes to the database.
Available since 3.5