Possibly wrong SQL with ExpressionPredicate
See original GitHub issueFirst I must say that the final result is working as expected. But when I tried to see generated SQL through SQL Server Profiler I think that it have unnecessary NOT Boolean expression.
This is my ExpressionPredicate
public static Expression<Func<Employee, Department, bool>> DepartmentPredicate => ( e, d ) => e.DepartmentId == d.DepartmentId && !d.Deleted;
And this is generated SQL
SELECT
*
FROM
[Common].[Employee] [t4]
LEFT JOIN [Common].[Department] [t1] ON [t4].[DepartmentId] = [t1].[DepartmentId] AND NOT (1 = [t1].[Deleted])
Notice NOT (1 = [t1].[Deleted])
.
I think this should be 0 = [t1].[Deleted]
.
Any thoughts on this?
Environment details
linq2db version: 1.9.0
Database Server: SQL Server
Framework version: .NET Framework 4.6.1
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Using a between predicate in CASE expression - sql
The first example is the correct query. There is no performance penalty for using CASE this way, that's just how you write it...
Read more >Wrong query generation when using Contains inside ...
Contains() method I'm getting a bad sql query like the one in your first post: WHERE Content LIKE ('%' + @__content_0) + '%'...
Read more >Possibly wrong expressions
Why is it bad? Murphy's Law dictates that the slight risk of the expression turning wrong eventually means that it should better be...
Read more >Overview of Predicates | InterSystems SQL Reference
A predicate is a condition expression that evaluates to a boolean value, either true or false. Predicates can be used as follows: In...
Read more >Search Conditions and Predicates
A predicate is an SQL expression that evaluates a search condition that is either TRUE, FALSE or UNKNOWN. TRUE means the expression is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think we can do something in that area in V2. For bit fields it should work.
Another voice to use 0 as baseline. Working on Access ODBC driver support I’ve discovered that it is not always 1 or 0… it could be -1 and 0