4.7 Action parameter support
Since Web API OData V5.5-beta, it supports the following types as action parameter:
- Primitive
- Enum
- Complex
- Entity
- Collection of above
Let’s see how to build and use the above types in action.
CLR Model
Re-use the CLR models in function sample.
Build Edm Model
Same as build Edm Model in function sample, but change the helper function as BuildAction().
Primitive and Collection of Primitive parameter
Configuration
In BuildAction(), we can configure an action with Primitive
and collection of Primitive
parameters:
Routing
In the CustomersController
, add the following method:
Request Samples
We can invoke the action by issuing a Post on ~/odata/Customers/Default.PrimitiveAction
with the following request body:
Enum and Collection of Enum parameter
Configuration
In BuildAction(), we can configure an action with Enum
and collection of Enum
parameters:
Routing
In the CustomersController
, add the following method :
Request Samples
We can invoke the action by issuing a Post on ~/odata/Customers/Default.EnumAction
with the following request body:
Complex and Collection of Complex parameter
Configuration
In BuildAction(), we can configure an action with Complex
and collection of Complex
parameters:
Routing
In the CustomersController
, add the following method :
Request Samples
We can invoke the action by issuing a Post on ~/odata/Customers/Default.ComplexAction
with the following request body:
Entity and Collection of Entity parameter
Configuration
In BuildAction(), we can configure an action with Entity
and collection of Entity
parameters:
It’s better to call EntityParameter<T>
and CollectionEntityParameter<T>
to define entity and collection of entity parameter.
Routing
In the CustomersController
, add the following method :
Request Samples
We can invoke the action by issuing a Post on ~/odata/Customers/Default.EntityAction
with the following request body:
Know issues
-
It doesn’t work if “null” value in the collection of entity in the payload. See detail in #100.
-
It doesn’t work if anything else follows up the collection of entity in the payload. See detail in #65
Null value
If you invoke an action with a ‘null’ action parameter value, please don’t add the parameter (for example, "p1":null
) in the payload and leave it un-specified. However, for collection, you should always specify it even the collection is an empty collection (for example, "p1":[]
).
Thanks.
For un-typed scenario, please refer to untyped page.