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:
public static 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?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156