English 中文(简体)
SubSonic OpenExpression/CloseExpression
原标题:

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?

最佳回答

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>();
问题回答

暂无回答




相关问题
Debugging SQL in ASP.NET

private void BuildGridView2() { GridView1.DataSource = new Select() .From("NewsReleases") .Where("RelMonth").IsEqualTo(this.ddlAward.SelectedValue) .And("RelYear").IsEqualTo(this....

SubSonic Error with MySql CONVERT()

I has encountered conversion from integer to string with MySql+SubSonic3 (it generates wrong SQL query). After I found root of the problem in SubSonic sources and fixed it, everything works fine, but ...

SubSonic OpenExpression/CloseExpression

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

Grouping with SubSonic 3

I have the following table "GroupPriority": Id Group Priority 1 1 0 2 2 0 3 3 0 4 2 1 5 1 1 6 2 2 7 ...

Subsonic Linq guid problem

The construtor Void .ctor(System.Guid, Int32) is not supported. this error occured with the following statements: var Test = from r in db.UserRoles join p in db.UserPermissions on new { r....

热门标签