question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possibly wrong SQL with ExpressionPredicate

See original GitHub issue

First 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:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sdanylivcommented, Sep 8, 2017

I think we can do something in that area in V2. For bit fields it should work.

0reactions
MaceWinducommented, Apr 20, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found