For a clean data model, I'm going back and forth on this...
Using an approval workflow as an example, let's say in my web application I have a page that lets a user flag a MyEntityObject
for approval. MyEntityObject
has a few properties that control its approval workflow, so I have a common utility method out there called FlagForApproval(MyEntityObject eo)
.
Should the page call FlagForApproval() to set necessary properties only and then call SaveChanges() when it's ready, or should FlagForApproval() save the changes?
Having the utility method save changes seems like it's doing a little more than it's asked to do (what if it was just one step in a series of operations?), but at the same time, making the page call SaveChanges() and commit the data to the DB seems like it could be considered too close to data layer responsibilities.
Thoughts?
(Update: FWIW, so far I have been having utility methods call SaveChanges(), that way the page only has one set of exceptions to handle, whether validation or data.)