I’m wondering if it is possible to use a substringof (or similar?) filter for oData for an int field? Becuase I’d like to query all of my Enquiries based off of their EnquiryID but I want it to be a contains and not an exact match. Is this possible to do a cast/convert?
Here is my query so far:
/api/Enquiries?filter=substringof('123', EnquiryID)
But I get the following error:
Method 'Boolean Contains(System.String)' declared on type 'System.String'
cannot be called with instance of type 'System.Int32'
I’d like it to return all Enquiries which contain 123 in their EnquiryID. I also get the same when using a DateTime type..
Edit
Here is my Get method in my Enquiries controller:
[Queryable]
public IQueryable<EnquiryDTO> Get()
{
var query = from enquiry in context.Enquiries
select new EnquiryDTO
{
CustomerID = enquiry.CustomerID,
OrderDate = (DateTime)enquiry.EnquiryDate,
OrderID = enquiry.EnquiryID,
Owner = enquiry.Owner
};
return query.AsQueryable();
}
This is not possible. OData doesn’t support conversion of primitive types in the query. If nothing else, the trouble would come with what format to use (especially for things line date time and such).
You could write a service operation to handle this for you though (assuming your query provider supports this).