Why does InvalidOperationException get thrown when deleting some entity instances, while UpdateException gets thrown for others?

There can be two different exceptions because there are two layers where this check is applied. First if you mark an object as deleted and execute SaveChanges EF will check its internal storage where all loaded objects are tracked. If EF finds that any tracked order related to the deleted customer is also not marked as deleted it will fire an exception (probably InvalidOperationException ).

If there is no tracked related order EF will execute delete operation in the database where FK relation triggers an error. This error is captured by EF and an exception is throwm (probably UpdateException with inner database related exception).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions