I am using a SQL Server database, Entity Framework 6, OData Webservice 4 and ASP.NET Web API 2.2 for OData.
To fetch specific objects from the remote server, the call looks like this:
DataServiceContext context = ...;
DataServiceQuery query = context.CreateQuery<SomeType>(...);
Expression<Func<SomeType, bool>> filterExpression =
item => item.SomeID.ToString().Contains("23");
IQueryable<SomeType> queryResult = query;
queryResult = queryResult.Where(filterExpression);
queryResult.ToList();
This goes wrong on execution because ToString()
is not possible to the SomeID
field, which is an integer.
But the OData definition has something like cast(..., Edm.String)
to be used in the query URL. The framework just doesn't use it, when I use ToString()
on the LINQ side.
(I can't even send the stupid filterExpression
via a DataServiceActionQuery
to handle it inside the controller on the service side. Seems like
Expression<Func<...>>
is not supported to be passed as a BodyOperationParameter
to the service action.)
What can be done? How can it be done?
My am is a fulltext search among numeric fields, returning only matching datasets of SomeType
.