Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

OData Query Replacing Characters

$
0
0

Hi, I am new to using OData querying and have been tasked with replacing database calls with our new REST web API using HTTP Web Requests.

I am using OData querying to do a search based upon the text the user wishes to search from. At the moment I have:

publicstatic async Task<List<HorseJson>>SearchForHorses(string textSearch,HorseRacingClient gsaClient){
        textSearch = textSearch.Replace("''","");
        textSearch = textSearch.Replace(".","");
        textSearch = textSearch.Replace(" ","");
        textSearch = textSearch.Replace("-","");
        textSearch = textSearch.Replace("(","");
        textSearch = textSearch.Replace(")","");
        textSearch = textSearch.Replace("*","");
        textSearch = textSearch.Replace("\"","");string query =string.Format("contains(horseName,{0})&$top=50&$orderby=horseName", textSearch);List<HorseJson> horseData = await gsaClient.SendODataRequest<HorseJson>("horses?$filter="+ query);return horseData;}


As you can see I am stripping out invalid characters from the textSearch.

I am querying the 'horseName' column field, but I need to strip the invalid characters out from that too so we can get a similar match.

This is possible to do in LINQ somewhat by doing something like:

textSearch = textSearch.Replace("-","");
db.Horses.Where(x => x.HorseName.Replace("-","").Contains(textSearch)).ToList();

Is this possible for OData?

Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images