when I execute these operators( >
and >=
) lambda expression in entity framework. both are getting same results.
db.Companies.where(Company => (Compare(Convert(Company.Name), "y") > 0))
db.Companies.where(Company => (Compare(Convert(Company.Name), "y") >= 0))
Is that issue with Lambda expression compare operator?
i changed to
db.Companies.where(Company => (Compare(Convert(Company.Name), "y") > 1))
- No results. Its not correct
db.Companies.where(Company => (Compare(Convert(Company.Name), "y") >= 1))
- 64 results
source code
case operatorType.Greater: return Expression.GreaterThan(Expression.Call(typeof(string),
"Compare", null, new[] { argLeft, argRight }),
Expression.Constant(1, typeof(int)));
case operatorType.GreaterEqual: return Expression.GreaterThanOrEqual( Expression.Call(typeof(string), "Compare", null, new[] { argLeft, argRight }),
Expression.Constant(1, typeof(int)));
If you're gettnig the same results, means that there is no Company.Name
equal to "Y"
Why would you expect the answer to be different.
- What does
Compare
do?
- What does
Convert
do?
- What does
Compare(Convert(Company.Name), "y")
evaluate to?
If it evaluates to 1
or greater then both answers would be correct.
If you have the same number of results for both queries then it means that (Compare(Convert(Company.Name), "y")
is never equal to zero. If it is anything greater than zero both queries will return it; if it's anything less than zero then neither query will return it.
Thanks for all responses The Lambda expression query is correct only.
db.Companies.where(Company => (Compare(Convert(Company.Name), "Test") > 0))
db.Companies.where(Company => (Compare(Convert(Company.Name), "Test") >= 0))
I changed the "right arg" value to "Test". I have one record 'Name' with Test. executed the following query.
db.Companies.where(Company => (Compare(Convert(Company.Name), "Test") > 0))
and shown the results 105(here Name with 'Test' is not shown. - Correct
Then I executed this
db.Companies.where(Company => (Compare(Convert(Company.Name), "Test") >= 0))
and shown the results 106(here Name with 'Test' is shown) - Correct