Show / Hide Table of Contents

    SqlBuilder.EmbeddedOn(string left, ISqlParameter parameter) Method

    .NET Standard 2.x

    Creates an ISqlJoinCondition object which represents a search condition that can be used (enclosed in parentheses) when building the ON clause. Specifies a SQL expression on the left of the operator and a SQL parameter on the right of the operator. The operator is '='.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

     public static ISqlJoinCondition EmbeddedOn(string left, ISqlParameter parameter);
    

    Parameters

    left System.String

    A SQL expression on the left of the operator.

    parameter SnapObjects.Data.ISqlParameter

    An ISqlParameter object which represents a SQL parameter.

    It can be created by calling the SqlBuilder.Parameter method.

    Returns

    SnapObjects.Data.ISqlJoinCondition

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

    Remarks

    The newly created search condition is enclosed in parentheses. If the returned ISqlJoinCondition object is used to add another search condition, both of these search conditions will be enclosed in the same pair of parentheses.

    Examples

    The following code example demonstrates how to use the EmbeddedOn(string left, ISqlParam parameter) method to set the condition to join one table with another.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.SqlBuilderExamples
    {
        public class EmbeddedOnExample
        {
            private SchoolContext _context;
    
            public EmbeddedOnExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example3()
            {
                ISqlQueryBuilder sqlQueryBuilder = new SqlQueryBuilder();
    
                // Defines an embedded JOIN condition.
                var join = SqlBuilder.EmbeddedOn("Department.DepartmentID",
                        SqlBuilder.Parameter<int>("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] = @departmentid
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon