Show / Hide Table of Contents

    ISqlJoinOnBuilder.OnValue(string left, object value) Method

    .NET Standard 2.x

    Creates an ON clause and adds a search condition to it. Specifies the SQL expression on the left of the operator and a specific value on the right of the operator. The operator is '='.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlJoinOnAndOr OnValue(string left, object value);
    

    Parameters

    left System.String

    An expression on the left of the operator.

    value System.Object

    The specific value on the right of the operator.

    Returns

    SnapObjects.Data.ISqlJoinOnAndOr

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

    Examples

    The following example uses the OnValue method to set the condition to join one table with another.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlJoinOnBuilderExamples
    {
        public class OnValueExample
        {
            private readonly SchoolContext _context;
    
            public OnValueExample(SchoolContext dataContext)
            {
                // Sets data context.
                _context = dataContext;
            }
    
            public void Example1()
            {
                var sqlQueryBuilder = new SqlQueryBuilder();
    
                // 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 = 1.
                sqlQueryBuilder
                    .Select("Department.DepartmentID")
                    .Select("Department.Name")
                    .Select("Course.Title")
                    .From("Department")
                    .Join("Course")
                    .OnValue("Department.DepartmentID ", 1);
    
    
                // 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 [Course]
                  ON [Department].[DepartmentID] = 1
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon