web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

OData Query Replacing Characters

(0) ShareShare
ReportReport
Posted on by

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?
I have the same question (0)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
MVP-Daniyal Khaleel Profile Picture

MVP-Daniyal Khaleel 125

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 97 Super User 2025 Season 2

#3
Erin Lubben Profile Picture

Erin Lubben 73

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans