Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1013461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:06:19+00:00 2026-05-16T10:06:19+00:00

I am trying to convert the following SQL into Subsonic syntax using the SqlQuery

  • 0

I am trying to convert the following SQL into Subsonic syntax using the SqlQuery functionality:

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 <= FMTR.EndDate or FMTR.EndDate IS NULL)
AND (CS.IsHistory = 0 OR CS.IsHistory = NULL)
WHERE FMTR.FamilyMemberId = @FamilyMemberId

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.

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();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:06:19+00:00Added an answer on May 16, 2026 at 10:06 am

    You can always check what query subsonic generates for you with the BuildSqlStatement() method:

    SqlQuery query = DB.Select().From<Product>();
    String output = query.BuildSqlStatemtent();
    

    But I think I know what the problem is: SubSonic2 Join methods don’t support joining on multiple columns as far as I know: subsonic 2 join on multiple columns

    So you basically you have two options.

    a) do a “comma join”

    SELECT * FROM table1
    INNER JOIN table2 ON table1.id = table2.table1_id
    

    is the same as this query below but more readable

    SELECT * FROM table1, table2
    WHERE table1.id = table2.table1_id
    

    At least that’s true for mysql

    Edit: That won’t work with subsonic as I figured out in my question (but have forgetten)

    http://www.mysqlperformanceblog.com/2010/04/14/is-there-a-performance-difference-between-join-and-where/

    b) Use an InlineQuery which is subsonic’s backdoor to execute plain sql.

        private class Process
        {
            public Int64 Id { get; set; }
            public string User { get; set; }
            public string Host { get; set; }
            public string Db { get; set; }
            public string Command { get; set; }
            public string State { get; set; }
            public string Info { get; set; }
        }
    
        var result = DB.Query().ExecuteTypedList<Process>("SHOW FULL PROCESSLIST");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert the following SQL into NHibernate: SELECT * FROM dbo.Customer
I am trying to convert the following SQL into a LINQ expression SELECT COUNT(ID)
I am trying to convert following table data into nested array using PHP. I
I'm trying to convert the following list into a select list so it can
I am trying to convert following SQL query to linq; select Or.Amount, Usr.Name, Usr.Email
I'm trying to convert the following SQL query to an ICriteria in NHibernate. SELECT
I'm trying to convert the following statement from SQL Server to Oracle, but everything
I have to perform the following SQL query: select answer_nbr, count(distinct user_nbr) from tpoll_answer
I am trying to convert the following query from SQL server based code to
I am trying to convert the following code from Trefethen's Spectral Methods in MATLAB

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.