1

Closed

Overriden CreateLink method does not work

description

I derive my controller class from EntitySetController<TEntity, TKey>

I have overriden the CreateLink method of base class:
public override void CreateLink(int key, string navigationProperty, Uri link)
{
}
The link parameter argument is always passed in as null, even though the body contains an Url:
POST http://localhost:34852/Channels(1)/$links/SIGNALS HTTP/1.1
Accept: application/json;odata=minimalmetadata
DataServiceVersion: 3.0,3.0;
MaxDataServiceVersion: 3.0
Content-Type: application/json;odata=minimalmetadata;streaming=true;charset=utf-8
Host: localhost:34852
Content-Length: 53
Expect: 100-continue

{
  "url":"http://localhost:34852/Signals(20000)"
}
Workaround:
It only works correctly by specifying again the [FromBody] attribute in the method signature of overriden method:
public override void CreateLink(int key, string navigationProperty, [FromBody] Uri link)
{
}
I believe this is a bug, since the mechanism works with the key parameter, where [FromODataUri] attribute is specified in the base class and I do not have to repeat it in overidden method.
Closed Jul 5, 2013 at 4:42 AM by eilonlipton
Per RaghuRam's comment, this is technically by design - based on some unfortunate implementation decisions that we had made before. Our new guidance will likely be to generally avoid using EntitySetController directly. We will guide users to use the new Scaffolding system that we are making available and we plan to add an OData Scaffolder to the list. That scaffolder will effectively generate a custom EntitySetController in your app and will be a lot easier to customize to suit your needs.

comments

raghuramn wrote Mar 6, 2013 at 7:35 PM

Parameter attributes are not inherited in CLR i.e if you have a BaseMethod(param1) with an attribute and then override the 'BaseMethod', the attribute will not be present on param1 of overridden method.

This works fine for GetEntityByKey and other methods in EntitySetController as they are not the actual actions that get invoked. The actual action is still on the base class EntitySetController and just invokes these overridden methods. So the overridden methods don't have to use any attributes.

That said, we should have just followed this delegation pattern so that customers don't accidentally forget the attributes in their controllers. It kind of has an inconsistent feel right now with some methods requiring the attribute and some not.

HongmeiG wrote Mar 29, 2013 at 11:04 PM

Yes, we should have a pretty good default for the common case so that user won't need to go attribute the parameters.