Action and Function are two similar feature in the OData V3 standard. OData V2 standard specifies a standard way to perform CRUD operation on stored data. In OData V3, more sophisticated operations are specified. These two methods are called Action and Function.
Both Action and Function are operations on the server side, then what are the differences between Action and Function?
The difference between Action and Function are the restrictions imposed upon them. Function is restricted that it cannot have side effect on the data, under the hood, function can read/query the entities that you created but if it deletes/updates them, it will be considered to be an illegitimate function. Function must return a result. Action may have side effect, however it is not necessarily return data.
When to use Function?
Function should be used when the result is required but not needed.
When to use Action?
Action should be used when we need to operate on the data where side effects are expected.
Can we use Action for Function?
Yes, you can use action for function because Action should work for scenarios where there is no side effect, further more, Action can also return data. It is not required to return data.
Here, you may recall the function vs procedure in SQL and PASCAL. Indeed, they are similar, just like procedure is a superset of function, here action is the superset of function.