Tuesday, May 18, 2010

DataContext OnDelete partial method doesn't delete

When using the OnDelete or OnUpdate partial methods in the DataContext (to say, cascade deletes to a child object) you may find that the object itself doesn't get deleted.

This was surprising to me. The reasoning makes sense, though. These partial methods totally replace the regular delete processing. They aren't a "pre" or "post" delete; they are "instead of" delete.

To make the original object actually get deleted, you should call ExecuteDynamicDelete(instance).

As seen here.

No comments: