Question

I'm adding a "WhatIf" switch (inspired by the Powershell -WhatIf switch) to my app, that just simulates data processing, without persisting any actual data changes back to the EF storage.

The way I hoped to implement this is simply by adding a check before calling SaveChanges(), like this:

if (WhatIf == false)
  efEntities.SaveChanges()

This way, the rest of the application can make changes as normal, and so long as SaveChanges() is never called, I don't have to worry about any changes being made accidentally.

Would this work? I'm worried that SaveChanges will get called by other parts of EF, such as Dispose, or something like that?

Thanks!

Was it helpful?

Solution

It will work. EF doesn't call SaveChanges itself. Developer is always responsible for persisting changes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top