-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG]Excluding And and Or Expressions #1633
Comments
@kampilan Done. It will be present in the next incremental release. |
@kampilan I am curious, why is this needed in practice? (Not criticizing in any way, just want to learn) |
@lbnascimento Do we or will we have the same form in LiteDB string expressions? |
@lbnascimento While it could be done, I'm not sure there's any point to it. |
It's needed because it is in fact a legitimate expression. Like me, most people use Expression.And and Expression.Or. Technically one should use AndAlso and OrElse. I have in fact changed my implementation to use AndAlso and OrElse. It is more correct to do so. But And and Or still need to be supported in this use-case because they are perfectly valid. |
@kampilan I think @nightroman was talking about having actual non-short-circuit operators in BsonExpressions, which I don't think is useful. The solution that you proposed in your first post (and which was implemented, by the way) merely maps |
I am confused by the example TestPredicate<User>(x => x.Salary > 50 && x.Name == "John", "((Salary > @p0) AND (Name = @p1))", 50, "John");
TestPredicate<User>(x => x.Salary > 50 & x.Name == "John", "((Salary > @p0) AND (Name = @p1))", 50, "John");
TestPredicate<User>(x => x.Salary > 50 || x.Name == "John", "((Salary > @p0) OR (Name = @p1))", 50, "John");
TestPredicate<User>(x => x.Salary > 50 | x.Name == "John", "((Salary > @p0) OR (Name = @p1))", 50, "John");
|
These are bitwise AND and OR operators. They operate on integers and return integers. Why in the above cases they are treated as Boolean operators is not clear. Technically, translation to string expressions is even wrong. Maybe I miss something simple. |
@nightroman They are overloaded operators: between two integers, they act as bitwise and/or; between two bools, they act as non-short-circuit logic operators. Check the official C# documentation. |
Ah, I see now. Yes, learned something new! TBH, never used & and | as Booleans for many years :) |
lbnascimento sorry 2 discussions going on at the same time. I agree unneeded, nightroman I also learned something new. In my opinion poor naming and documentation on MS part. |
Which LiteDB version/OS/.NET framework version are you using. (REQUIRED)
5.0.7
Describe the bug
The code below is missing And and Or
Code to Reproduce
Not needed
Expected behavior
It makes no sense to exclude And and Or as they differ from AndAlso and OrElse only in logical short-cutting which appears to be inconsequential to your use-case.
X == 0 & Y == 1 And Evaluates entire expression even if X != 0
X == 0 && Y == 1 AndAlso. This shortcuts the expression if X != 0
In you use-case this nuance is meaningless so why exclude them?
Thanks
Jim
The text was updated successfully, but these errors were encountered: