Hi,
I am trying to write a query using Linq (LLBLGen) that will do a case insensitive search. The database collation is case sensitive.
This is what I am doing - q is IQueryable<>
q = q.Where(a => a.RegistrationNumber.Contains(aircraftFilter.RegistrationNumber, new IgnoreCaseComparer()));
and IgnoreCaseComparer is
class IgnoreCaseComparer : IEqualityComparer<string>
{
public CaseInsensitiveComparer myComparer;
public IgnoreCaseComparer()
{
myComparer = CaseInsensitiveComparer.DefaultInvariant;
}
public IgnoreCaseComparer(CultureInfo myCulture)
{
myComparer = new CaseInsensitiveComparer(myCulture);
}
#region IEqualityComparer<string> Members
public bool Equals(string x, string y)
{
return myComparer.Compare(x, y) == 0;
}
public int GetHashCode(string obj)
{
return obj.ToLower().GetHashCode();
}
#endregion
}
When doing the above I get the following error:
Error 71 The type arguments for method 'System.Linq.Enumerable.Contains<TSource>(System.Collections.Generic.IEnumerable<TSource>, TSource, System.Collections.Generic.IEqualityComparer<TSource>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
When I specify the type string explicitly it cannot resolve the lambda expression.
This works in Linq can I get this to work in Linq for LLBLGen and if not how can I do a case insensitive search?
Thanks
Pieter