Search code examples
c#subsonic

Subsonic Query (ConditionA OR ConditionB) AND ConditionC


How do I build a query in Subsonic that of this format

(ConditionA OR ConditionB) AND ConditionC

Iv tried various approaches but I cant seem to get the desired result.

Here is one thing i tired:

Query q = Challenge.CreateQuery();
      q.WHERE(Challenge.Columns.ChallengeeKey, playerKey)
      .OR(Challenge.Columns.ChallengerKey, playerKey);
       q.AND(Challenge.Columns.Complete, false);

Solution

  • I'm using Subsonic 2.2, I tried a few variations on Rob's example but kept getting an exception with the message: "Need to have at least one From table specified"

    In the end this achieved the desired result:

              Challenge challenge = new Select().From(Challenge.Schema)
               .WhereExpression(Challenge.Columns.ChallengerKey).IsEqualTo(playerKey)
               .Or(Challenge.Columns.ChallengerKey).IsGreaterThan(playerKey)
               .AndExpression(Challenge.Columns.Complete).IsEqualTo(false)
               .ExecuteSingle<Challenge>();