I am creating a webpage that creates documents in a highly templated way.
Part of the documents though involves a calculation. My problem is that there are an abundance of different calculations it can be.
What I’d love to have is to create a lambda expression and persist it to the database (SQL, MongoDB, or DocumentDB) directly. This would mean that upon retrieving the template it would simply be a matter of invoking the expression against the data. Unfortunately it does not seem to be able to be done in a straightforward manner. For all the advancements in C# being more functional. Database persistence of functions is still not something that’s available
Store Name of Calculation in an Enum (and enum in the DB) then execute calculation based on the value of the enum.
- Easy to store
- Easy to understand
- The code will be confusing
- Not actually storing the calculation. Just the promise it wont change
- Can likely be very powerful
- Should be easy to understand the value stored
- Unlikely the interop is smooth
- Another language adds to complexity
Option 3 :
Some form of text storage and Eval.
- Easy to understand whats going on
- External Library
- Likely very slow
- Lots of restrictions on actions.
Something else I haven’t even considered. Maybe you have the right answer.