Show / Hide Table of Contents

    SqlBuilder.On(string left, string right) Method

    .NET Standard 2.x

    Creates an ISqlJoinCondition object which represents a search condition that can be used when building the ON clause. Specifies SQL expressions on both the left and right of the operator. The operator is '='.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

     public static ISqlJoinCondition On(string left, string right);
    

    Parameters

    left System.String

    A SQL expression on the left of the operator.

    right System.String

    A SQL expression on the right of the operator.

    Returns

    SnapObjects.Data.ISqlJoinCondition

    Returns the ISqlJoinCondition object which can be used to add more search conditions to the ON clause.

    Examples

    The following code example uses the On method to set the condition to join the "Department" table with the "Course" table.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.SqlBuilderExamples
    {
        public class OnExample
        {
            private SchoolContext _context;
    
            public OnExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example1()
            {
                var sqlQueryBuilder = new SqlQueryBuilder();
    
                // Defines a JOIN ON condition.
                var join = SqlBuilder
                    .On("Department.DepartmentID", "Course.DepartmentID");
    
                // Creates a SQL statement.
                var query = sqlQueryBuilder
                    .Select("Department.DepartmentID")
                    .Select("Department.Name")
                    .Select("Course.Title")
                    .From("Department")
                    .Join("Course")
                    .On(join);
    
                // Converts to raw SQL for the database corresponding to the data context.
                string sql = query.ToSqlString(_context);
    
                Console.WriteLine(sql);
    
                /*This code produces the following output:
                
                SELECT
                [Department].[DepartmentID],
                [Department].[Name],
                [Course].[Title]
                FROM [Department] JOIN [Course]
                ON [Department].[DepartmentID] = [Course].[DepartmentID]
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon