Deleting Entities

Deleting entities is also a simple task. You first need to get the instance of the entity you want to remove and then invoke the ObjectSet(Of T).DeleteObject method. The following code shows how to get the instance of the specified product and then to remove it first from the model and then from the database:

image

Same as in previous code, we take advantage of the Single method that throws an InvalidOperationException if the object does not exist.

Deleting Entities with Relationships

In this chapter you see simplified examples focusing on the technology. In some situations you need to delete entities with relationships; for example, ...

Get Visual Basic® 2010 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.