I have a database created with a SQL_Latin1_General_CP1_CI_AS collation (which is case insensitive). I'm creating LINQ Expressions and trying to make "Contains" method which should compare strings in a case sensitive way.
I know that I can force collation if I use something like:
CHARINDEX(N'foo' COLLATE SQL_Latin1_General_CP1_CS_AS, 'something Foo') > 0
but since I'm building expressions using LINQ to create a query, my code looks like:
using System.Linq.Expressions;
private Expression Contains(Type type, string value, Expression propertyExpression)
{
var searchValue = Expression.Constant(value, typeof(string));
var method = propertyExpression.Type.GetMethod("Contains", new[] { type });
var result = Expression.Call(propertyExpression, method, searchValue);
...
}
So, if I'm trying to use this Contains method for word 'foo', rows with 'Foo' will also be returned (which I don't want).
Is there a way that I can expand this Expression so that I can specify Case Sensitive comparison?