I could return nothing .. I could return true/false to show if there are any problems.. I could return an int being the primary key of what was inserted or updated.. I could create a custom object to return more information.. perhaps hold a collection of all the validation errors or something that may have occurred..
So it is not something I am stuck with but I just seem to randomly pick different way so would like to hear a best practice for these common functions..
I am using C#/Entities/Repository pattern.
It's really a matter of personal preference. You might want to distinguish between commands and queries.
So creates, updates and deletes would be commands and I would expect them to return void.
Reads would be queries and would return IQueryable.
However, if you routinely want to use an inserted object directly after inserting it you may want to return the object as a result of the insert.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With