1

大家好!我正在尝试构建一个类似这样的查询:

其中 column = "value" AND column2 = "value" AND (column3 = "value" OR column4 = "value")

我有这个代码:

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>();

问题是 SubSonic 在括号后添加了 And。我怎么能否定它?

4

1 回答 1

4

你应该能够做到:

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>();
于 2009-11-16T19:12:30.740 回答