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!

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top