JayData.org

How to invoke OData FunctionImports (aka Service Operations) with JayData and JavaScript

Author: Peter Aron Zentai September 18th, 2012

, , ,


Context level functions are a powerful feature of Entity Framework, more so with OData exposing them with full metadata description. Leaning on this metadata JayData provides you with a super simple, JavaScript native way to invoke server side functions as if they were just simple functions.

At the end of this writing check the limitations of JayData service operations support.

Given the following three exposed function on our imaginary (and always reappearing) Northwind data context:

The first and third functions (GetCheapProducts and AddTwoNumbers) are simpler to deal with, those function return so to say static content: the actual result is produced within the function scope. The second function (GetBeverages) however return only a Queryable – that guess what behaves exactly the same way as a published EntitySet: you can further query its results with standard predicates that are later combined on the server side.

Nevertheless invoking them from JayData follows the same pattern:

Invoke functions without parameters

Results

CropperCapture[56]

Invoke a function and filter its results

Notice that predicate strings are always allowed where ever function predicates can be used. The above code can be more terse with using a string predicate.

The network request

The result

CropperCapture[57]

Passing parameters to service operations

When parameters are present it’s always the last argument that is treated as the result handler callback, all preceding ones are passed to the service operation.

The result: 30 Smile

, , ,