Conditions in LoadSelect not replacing value?

The following query is not working as expected:

        var response = db.LoadSelect(db.From<Activity>()
           .Where(x => x.AccountID == request.AccountID)
           .And(x => x.Active == true || request.IncludeInactive)
           .And(x => x.Deleted == true || request.IncludeDeleted)
           .OrderByDescending(x => x.DateCreated)
           .Limit(0, 50));

produces the following LastCommandText:

"SELECT `ID`...... `AccountID`     // All fields here... 
FROM `Activity`
WHERE (((`AccountID` = @0) AND ((`Active` = @1) OR (1=0))) AND ((`Deleted` = @2) OR (1=0)))
ORDER BY `DateCreated` DESC
LIMIT 50 OFFSET 0"

This returns no results, however if i substitute the @ params with correct values the query is correct

Am I doing something wrong here?

The generated query indicates that both Request properties are false, is that expected?

Note: it’s effectively equivalent to this query:

var response = db.LoadSelect(db.From<Activity>()
   .Where(x => x.AccountID == request.AccountID)
   .And(x => x.Active == true)
   .And(x => x.Deleted == true)
   .OrderByDescending(x => x.DateCreated)
   .Limit(0, 50));

Does this return results?

1 Like

Apologies, it is indeed a bug in my code, my bad :confused: