I've been trying to call a stored procedure through Entity Framework and WCF Data Services (OData). It returns an entity not a complex type. Following walkthroughs found all over the web (like this one), I came up with this code inside my service:
[WebGet]
public IQueryable<Entity> GetEntitiesByParameterId(int parameterId)
{
return CurrentDataSource.GetEntitiesByParameterId(parameterId).AsQueryable();
}
Calling the proc this way: ~WcfService.svc/GetEntitiesByParameterId?parameterId=1
executes the stored procedure and returns entities that should be returned. No problem there.
Everything works well until I try to use $select OData option ie. ~WcfService.svc/GetEntitiesByParameterId?parameterId=1&$select=name
. Upon debugging, the method above runs without any error but it returns an Operation could destabilize the runtime error upon reaching the client. After so much research, apparently it is a very general error pointing to a lot of different causes. I haven't found one that really matches my particular problem. Closest are this and this but none of the solutions worked on my end.
Also, from the second article above:
This is a known limitation of WCF DS. ...
Second is that some of the queries won't work correctly because LINQ to EF needs little different LINQ expressions than LINQ to Objects in some cases. Which is the problem you're seeing.
It has been posted on 2012. If it its true, are there still no updates on this? And is there any other workaround to get the $select working on the stored proc call?
TL;DR:
Works:
~WcfService.svc/GetEntitiesByParameterId?parameterId=1
~WcfService.svc/GetEntitiesByParameterId?parameterId=1&$top=1
~WcfService.svc/GetEntitiesByParameterId?parameterId=1&$skip-5
~WcfService.svc/GetEntitiesByParameterId?parameterId=1&$filter={filter query}
~WcfService.svc/GetEntitiesByParameterId?parameterId=1&$expand=SomeNavigationProperty
Doesn't work:
~WcfService.svc/GetEntitiesByParameterId?parameterId=1&$select=name
Tech details:
EntityFramework 5, WCF Data Service 5.0, OData V3
*I've also tried upgrading to EF6 and WCF 5.6.2 and it still didn't work.
Any help would be appreciated. Thanks!
UPDATE:
After a little more fumbling through this, I tried not going through the stored procedure and just return a manually constructed List<Entity>
then returned it as queryable. Surprised to see that it still has the same error when $select is used. This may be a WCF Service Operation limitation and not particularly just for stored procedure calls. I went back to the documentation and it does show usage of other OData queries (top, expand & orderby) but nothing about $select.
This is merely an observation through my tests since I can't find much source for this particular problem. Any clarifications and other documentations are welcome.