Note that there are some explanatory texts on larger screens.

plurals
  1. POSubsonic 2.2 SqlQuery with Inner Join and Where
    primarykey
    data
    text
    <p>I am trying to convert the following SQL into Subsonic syntax using the SqlQuery functionality:</p> <pre><code>SELECT DISTINCT * FROM FamilyMemberTeamRole FMTR INNER JOIN TeamRole TR ON FMTR.TeamRoleId = TR.TeamRoleId INNER JOIN Team T ON T.TeamId = TR.TeamId LEFT JOIN FamilyMemberClassHistory FMCH ON FMCH.FamilyMemberClassHistoryId = FMTR.FamilyMemberClassHistoryId LEFT JOIN CBSClass CG ON CG.CBSClassGroupId = FMCH.CBSClassGroupId LEFT JOIN CBSClassSession CS ON CG.CBSClassGroupId = CS.CBSClassGroupId AND (CS.ClassStartDate &lt;= FMTR.EndDate or FMTR.EndDate IS NULL) AND (CS.IsHistory = 0 OR CS.IsHistory = NULL) WHERE FMTR.FamilyMemberId = @FamilyMemberId </code></pre> <p>I came up with this however something is wrong with my syntax on the last left join as I do not know how to compare values from within the SqlQuery to themselves.</p> <pre><code>SqlQuery sql = new Select().From(FamilyMemberTeamRole.Schema.TableName) .InnerJoin(TeamRole.TeamRoleIdColumn, FamilyMemberTeamRole.TeamRoleIdColumn) .InnerJoin(Team.TeamIdColumn, TeamRole.TeamIdColumn) .LeftOuterJoin(FamilyMemberClassHistory.FamilyMemberClassHistoryIdColumn, FamilyMemberTeamRole.FamilyMemberClassHistoryIdColumn) .LeftOuterJoin(CBSClass.CBSClassGroupIdColumn, FamilyMemberClassHistory.CBSClassGroupIdColumn) .LeftOuterJoin(CBSClassSession.CBSClassGroupIdColumn, CBSClass.CBSClassGroupIdColumn) .AndExpression(CBSClassSession.Columns.ClassStartDate).IsLessThanOrEqualTo(FamilyMemberTeamRole.Columns.EndDate) .Or(FamilyMemberTeamRole.Columns.EndDate).IsNull().CloseExpression() .AndExpression(CBSClassSession.Columns.IsHistory).IsEqualTo(false) .Or(CBSClassSession.Columns.IsHistory).IsNull().CloseExpression() .Where(FamilyMemberTeamRole.Columns.FamilyMemberId).IsEqualTo(this.FamilyMemberId) .Distinct(); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload