SqlExpression Syntax for And Operators in .Where

After upgrading from 5.0.2 to 5.6, I’ve had a few of my queries fail because of the way that OrmLite is translating the linq expression.

db.From(Of Table)
    .Where(Function(t) t.IsDeleted = False And t.IsActive = False)

but now after upgrading it has to be “AndAlso” otherwise I get an “Incorrect syntax” error

The same problem happens in C# when you use & instead of &&
I get the error System.Data.SqlClient.SqlException: 'Incorrect syntax near '&'.'

It’s easy enough to fix in our code, but it’s going to be a little hard to find all of the places where we should have AndAlso instead of And or && instead of & in all of the different queries.

I was wondering if that was an intentional change to the way it parses the linq statements or not?

Thanks

& and && are not the same operators, & is a bitwise and operator that should be used to apply a Bitwise AND operation against 2 integers, e.g:

db.Select<Table>(x => (x.Flags & 2) == 2);

Where the actual bitwise & operation is generated in SQL and executed by the underlying RDBMS which for this VB.NET Expression is generated as:

SELECT "Id", "IsActive", "IsDeleted" 
FROM "Table"
WHERE (("IsDeleted" = @0) & ("IsActive" = @1))

I’ve just created a quick VB.NET project to check that VB.NET And interprets this as a bitwise & operator that most RDBMS’s don’t support it being used in-place of a logical && or (aka AndAlso).

I’m assuming this behavior changed when OrmLite added support for Bitwise operations. You will need to update your source code to not use it within logical expressions.