Kourosh
Kourosh

Reputation: 789

odata unknown function cast

I have a web api project that host my models, in my .net application, when I query this :

static void TitleById(MoviesService.Container container, short id)
        {
            try
            {
                MoviesService.Title title = container.Title.Where(w => w.Id == id).SingleOrDefault();
                if (title != null)
                {
                    DisplayTitle(title);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }

the problem is not with the query, it's from id variable. the id variable is of the short type not an int. here is the exception message :

<?xml version="1.0" encoding="utf-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
  <m:code />
  <m:message xml:lang="en-US">An error has occurred.</m:message>
  <m:innererror>
    <m:message>Unknown function 'cast'.</m:message>
    <m:type>System.NotImplementedException</m:type>
    <m:stacktrace>   at System.Web.Http.ApiController.&lt;InvokeActionWithExceptionFilters&gt;d__1.MoveNext()&#xD;
--- End of stack trace from previous location where exception was thrown ---&#xD;
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&#xD;
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&#xD;
   at System.Web.Http.Dispatcher.HttpControllerDispatcher.&lt;SendAsync&gt;d__0.MoveNext()</m:stacktrace>
  </m:innererror>
</m:error>

and here is odata url :

"GET http://localhost:21401/odata/Title()?$filter=cast(Id,'Edm.Int32') eq 3&$top=2"

well, the type of Id property in my entites is short. how can I pass it to the query?

Thanks, If I have to bring more information, please tell me.

Upvotes: 0

Views: 1017

Answers (1)

Tan Jinfu
Tan Jinfu

Reputation: 3347

I found that cast is not implemented in FilterBinder.BindSingleValueFunctionCallNode in source code: https://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Http.OData/OData/Query/Expressions/FilterBinder.cs

One of the way to solve it is to download the code and implement yourself.

Upvotes: 2

Related Questions