object88
object88

Reputation: 760

OData Action without a target entity

Is it possible to have an OData Action that is not bound to a particular entity or instance, but rather can be invoked upon a collection? Such as...

http://server:port/MyOdataService/Notifications/ClearAll

where Notifications is a ResourceSet, and ClearAll is an action. I liken this to a static method in C#, somewhat.

The obvious workaround is to use a "global" action or an old ServiceOperation, but I would rather not have some of my operations scoped that high up or forced into using tedious names.

Upvotes: 1

Views: 728

Answers (2)

Ian Yates
Ian Yates

Reputation: 1354

I know this is an old question but I came across a solution to this earlier today. (I don't have the issue but I found this question and recall reading the solution - why not contribute the link between the two?)

There's an example at http://aspnet.codeplex.com/SourceControl/latest#Samples/WebApi/ODataActionsSample/ODataActionsSample.sln

Look at the NonBindableActionRoutingConvention.cs and NonBindableActionsController.cs files for what you need to do.

Upvotes: 0

Jen S
Jen S

Reputation: 4555

At the OData protocol level, it's valid to have an action parameter bound to a collection of entities. For example, if the Notifications entity set is made up of entities which are of type MyNamespace.Notification, then the binding parameter of the action will have a type of Collection(MyNamespace.Notification).

Within a WCF Data Services action provider, I believe this is possible by just making the ServiceAction.BindingParameter.ParameterType a CollectionResourceType (obtained via ResourceType.GetCollectionResourceType(/* notification type */)). (I haven't tried this out though.)

Upvotes: 2

Related Questions