I am currently comparing property values of type string using the string Equals method.
Example: f.rfgmodel.Equals(model, StringComparison.OrdinalIgnoreCase)
Now the problem I am running into is that for strings like ‘M&P9 Shield’ (a Firearm Model stored in my Accessories table in the DB), that has the ‘&’ symbol, the string Equals method doesn’t work.
Sadly, I cannot ignore the ‘&’ symbol in such model values, so stripping out the ‘&’ symbol from existing DB records in the DB is not an option.
Here is what my code looks like:
[Route("filter/{pcategory}")]
public IQueryable<AccessoryDto> GetAccessoryFilter(string pcategory = "", string model = "")
{
return db.Accessories.Where(f => (f.rfgacctype.Equals("holsters", StringComparison.OrdinalIgnoreCase) & f.rfgparentcategory.Equals(pcategory, StringComparison.OrdinalIgnoreCase) & f.rfgmodel.Equals(model, StringComparison.OrdinalIgnoreCase)))
.Select(AsAccessoryDto);
}
Example of my DB table: Accessory Table
I have searched quite a bit and the few matches don’t have a solution, much less provide enough hints to lead me in the right direction in attempting to resolve my current problem.
Example 1: C# String comparison fails for string having special character in it In this particular thread, the user @Biki left a comment to the first answer, stating that the Equals method doesn’t work. This is true.
Example 2: This one didn’t help either: Elastic Search-Search string having spaces and special characters in it using C#
Please if anyone could help with a solution of provide hints pointing me in the right direction. Thanks in advance. Much appreciated.