-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Query: | and & operators fail #5930
Comments
Any particular reason to use bitwise operators instead of logical operators on Boolean values? |
Thank you for fast reply. Reasons: _2. From C# specification point of view you can use both types (&&, || and &, |). It depends on your style of writing code. _3. Developers can by mistake (or by habit) write '&' instead of '&&'. And they don't know about the bug in their code until it occurs in production environment in some cases. It's bad that it's not a compile time error. It increases complexity (developer must keep in mind more dangerous 'cases' that compiler does not track) _4. Support the code written for EF 6. _5. Previous release candidates of EF Core (including recent RC2) supported both types of operators. And I don't know any notes in EFCore documentation that you decided to not support such operators. _6. I know it's not a reason but it doesn't increase complexity in EF Core. You can just use fully the same code as for && and ||. Thank you in advance! |
According to https://msdn.microsoft.com/en-us/library/ms176122.aspx The reason it worked till RC2 because we added code for translating bitwise operators to Sql after RC2. Previously it was being evaluated on client (in memory) which works fine. |
Which library emits expressions with bitwise operators instead of logical and/or? |
From C# point of view, && is boolean operator and & is bitwise operator, it has nothing to do with "style of code".
This is incorrect, both are bitwise operators, even though bitwise operator on boolean type returns in (C#) a boolean, it's still a bitwise operator.
If code goes production without even testing once it in development or integration environment that's the developers responsibility. It doesn't even give bad results, it throws an exception. You can't get a compile time error, since it's a valid C# expression. It's no different than using the wrong variable. |
I found a dupe of this issue: #6024 (except '|' operator). It was set to 1.1.0 milestone. I think you could close one of two issues. It seems that VB.NET developers prefer to use 'And' operator rather than 'AndAlso'. Just wanted to say that "For bool operands, & computes the logical AND of its operands" (from msdn). And I naturally expected this to work everywhere (in all C# code). "I don't recall ever seeing someone using & and | except from boolean Flags". I have seen. Especially young developers without C/C++ background. I cannot forbid them (as it's a part of C#, and nowhere is written: "do not use it with bools"). |
P.S. I agree with you that it would be better, if '&' didn't work with bool values. And I always advise developers to use '&&' instead. And for me it's not an issue now. Just wanted to notify you about changes between rc2 and rtm. I think you could close one of two issues. |
Cleared milestone. The dupe of this issue was in 1.1.0 milestone and this one was in backlog. |
After I migrated from '1.0.0-rc3-21052' to '1.0.0' I found that the following code fails:
however this code still works fine:
I cannot use the last one as temporary workaround, because failed code in 3rd party library.
Output:
Further technical details
EF Core version: 1.0.0
Operating system: Windows 8.1
Visual Studio version: 2015 Update 3
The text was updated successfully, but these errors were encountered: