string personName= "JoHn";
//(in my table iam already having a person named='john')
Func<Person, bool> predicate = (p) => p.Name== personName;
var res2 = dataContext.Persons.Any(predicate); //returns false
var res1 = dataContext.Persons.Any(p=>p.Name== personName); // returns true
I think with predicate its considering case of personName property while without it its just ignoring case.
Any one know why??
A
Func<Page, bool>is a delegate, which means you are running this in LINQ-to-Objects (i.e. in memory, in C#). .NET strings are case sensitive, so this will apply case.This version, however:
is using
IQueryable<T>and expression-trees; it will be executed as a TSQL filter, which will apply database rules. What happens here depends on how your DB is configured (it could be either case-sensitive or case-insensitive, depending on the database).If you want them both to use the same logic, then note the difference here:
The addition of
Expression<...>makes this an expression-tree, not a delegate, so it is “composed” and executed at the database (via TSQL translation), exactly the same as: