jmeckley wrote:
My first option would be to not keep this information db. Instead I would make this a read-only calculated property in the entity.
I would totally agree with you in a simple example like this one... but there are cases where the calculation is much more complex and is based on a set of criterias that could be different from time to time (like Currency exchange rates)...
Keeping such calculated values in your database could be interesting, especially if they are extensively used by a reporting/statistics module in your application.
About your idea of using triggers/sp/... and server side calculation, that would do it but the main problem is that they are rarely (if ever) supported by embedded database engines. Another criteria is that I would like the values of calculated fields to be displayed to the user (in some read-only UI controls) before he actually commits his work by pressing the save button.
Walaa wrote:
Use EntityValidation (ValidateEntityAfterSave), where you can calculate the total amount and set it just before the save.
So you would use the validation mechanism too.
For now the best I have found is overriding OnValidateFieldValue, because calculated values need to be shown to the user before the entity is actually saved (forgot to mention that in my previous post).
Thanks both of you for your valuable answers.