Show / Hide Table of Contents

    ISqlJoinBuilder.Join(ISqlBuilder sqlBuilder, string alias) Method

    .NET Standard 2.x

    Creates a table by joining the original table source with a new table source which is specified by a subquery generated by an ISqlBuilder object. You need to specify an alias for the new table source.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlJoinOnBuilder Join(ISqlBuilder sqlBuilder, string alias);
    

    Parameters

    sqlBuilder SnapObjects.Data.ISqlBuilder

    An ISqlBuilder object which represents a subquery.

    alias System.String

    The alias of the new table source specified by the sqlBuilder parameter.

    Returns

    SnapObjects.Data.ISqlJoinOnBuilder

    Returns an ISqlJoinOnBuilder object which can be used to create the condition on which the join is based.

    Examples

    The following code example demonstrates how to join a table with another using the JOIN method.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlJoinBuilderExamples
    {
        public class JoinExample
        {
            private readonly SchoolContext _context;
    
            public JoinExample(SchoolContext dataContext)
            {
                // Sets data context.
                _context = dataContext;
            }
    
            public void Example4()
            {
                var sqlQueryBuilder = new SqlQueryBuilder();
    
                // Defines a query, and gets the DepartmentID values and Title values from the "Course" table.
                var sqlBuilder = new SqlQueryBuilder();
                sqlBuilder.Select("DepartmentID")
                          .Select("Title")
                          .From("Course");
    
                // Gets the DepartmentID values and Name values from the "Department" table, and Title values from the "Course" table. 
                // Sets the condition to join the "Department" and "Course" tables: Department.DepartmentID = Course.DepartmentID.
                // Specifies "Course" as the alias for the "Course" table.
                sqlQueryBuilder.Select("Department.DepartmentID")
                                .Select("Department.Name")
                                .Select("Course.Title")
                                .From("Department")
                                .Join(sqlBuilder, "Course")
                                .OnRaw("Department.DepartmentID = Course.DepartmentID");
    
                // Converts to raw SQL for the database corresponding to the data context.
                string sql = sqlQueryBuilder.ToSqlString(_context);
    
                Console.WriteLine(sql);
    
                /*This code example produces the following output:           
                  SELECT
                    [Department].[DepartmentID],
                    [Department].[Name],
                    [Course].[Title]
                  FROM [Department]
                  JOIN (SELECT
                            [DepartmentID],
                            [Title]
                        FROM [Course]) AS [Course]
                  ON [Department].[DepartmentID] = [Course].[DepartmentID]
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon