By default ODataController performs case-sensitive search. How do we extend this behaviour to perform case-insensitive search.
public class NammaODataController : ODataController
{
[EnableQuery]
public IQueryable<FD> GetFD(ODataQueryOptions qo)
{
return _ctx.FDs.AsQueryAble();
//EF takes care to apply odata query operators internally
//after control passes from action
}
}
I referred this SO seems we can leverage Expression Tree, but at which extensiblility point?
Is there any way I could intercept the query and customise EF / Web Api piplelie to achieve this?
Here's an example: /FD?$filter=tolower(Pr_Name) eq tolower('TAMARA') - this should return all people with name 'Tamara' (case insensitive, could be 'TAMARA', 'tamara', 'Tamara', etc. Hope this will help, to put forward my point.
EDIT:
Case-senitivity in
ODATA Web API queries
has nothing to do with SQL Collation. This has been an issue with Microsoft OData framework.
With substringof operator
void Main()
{
var lower = _ctx.FD
.Where(sv => sv.Pr_Name.Contains("tamara"))
.Take(1)
.ToList();
Console.WriteLine("LOWER CASE AZURE SQL OUTPUT");
Console.WriteLine(lower);
Console.WriteLine("UPPER CASE AZURE SQL OUTPUT");
var upper = _ctx.FD
.Where(sv => sv.Pr_Name.Contains("TAMARA"))
.Take(1)
.ToList();
Console.WriteLine(upper);
}
With
eq
operator
void Main()
{
var lower = FD
.Where(sv => sv.Pr_Name == tamara A TOPOLESKI")
.Take(1)
.ToList();
Console.WriteLine("LOWER CASE AZURE SQL OUTPUT");
Console.WriteLine(lower);
Console.WriteLine("UPPER CASE AZURE SQL OUTPUT");
var upper = FD
.Where(sv => sv.Pr_Name == "TAMARA TOPOLESKI")
.Take(1)
.ToList();
Console.WriteLine(upper);
}