Show / Hide Table of Contents

    ISqlJoinOnBuilder.OnRaw(string clause, params ISqlParameter[] parameters) Method

    .NET Standard 2.x

    Creates an ON clause and adds a raw SQL to it.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlJoinOnAndOr OnRaw(string clause, params ISqlParameter[] parameters);
    

    Parameters

    clause System.String

    A string of raw SQL to be added to the ON clause.

    parameters SnapObjects.Data.ISqlParameter[]

    (Optional) An array of ISqlParameter objects which define the SQL parameters used in the raw SQL.

    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 code example uses the OnRaw method to set the condition (in raw SQL) for joining one table with another.

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

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon