views:

106

answers:

1

Hey All! I'm trying to construct a query that is something like this:

Where column = "value" AND column2 = "value" AND (column3 = "value" OR column4 = "value")

I have this code:

return new Select()
               .From(LessonChallenge.Schema)
               .Where(LessonChallenge.ChallengerStatusColumn).IsEqualTo("Finished")
               .And(LessonChallenge.ChallengeeStatusColumn).IsEqualTo("Finished")
               .OpenExpression()
                    .And(LessonChallenge.ChallengerAccountIDColumn).IsEqualTo(accountID)
                    .Or(LessonChallenge.ChallengeeAccountIDColumn).IsEqualTo(accountID)
               .CloseExpression()
               .OrderDesc("dateCompleted")
               .Paged(1, numItems)
               .ExecuteAsCollection<LessonChallengeCollection>();

Problem is that SubSonic is adding the And after the parenthesis. How can I negate that?

+2  A: 

You should be able to do:

return new Select()
           .From(LessonChallenge.Schema)
           .Where(LessonChallenge.ChallengerStatusColumn).IsEqualTo("Finished")
           .And(LessonChallenge.ChallengeeStatusColumn).IsEqualTo("Finished")
           .AndExpression(LessonChallenge.ChallengerAccountIDColumn).IsEqualTo(accountID)
                .Or(LessonChallenge.ChallengeeAccountIDColumn).IsEqualTo(accountID)
           .OrderDesc("dateCompleted")
           .Paged(1, numItems)
           .ExecuteAsCollection<LessonChallengeCollection>();
Adam
Thanks! Figured out AndExpression existed!
LookitsPuck