Show / Hide Table of Contents

    ISqlQueryBuilder.SelectRaw(string selectRaw, string builderAlias, params ISqlParameter[] parameters) Method

    .NET Standard 2.x

    Adds a raw SQL as a column to the select list of a SELECT clause, and specifies an alias for the raw SQL.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlQueryBuilder SelectRaw(string selectRaw, string builderAlias, params ISqlParameter[] parameters);
    

    Parameters

    selectRaw System.String

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

    It is usually a SQL subquery.

    builderAlias System.String

    The alias of the raw SQL.

    You can use the RemoveSelect method to remove this column by the alias of the raw SQL.

    parameters SnapObjects.Data.ISqlParameter[]

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

    Returns

    SnapObjects.Data.ISqlQueryBuilder

    Returns the current ISqlQueryBuilder object.

    Examples

    The following code example selects columns in raw SQL, sets a customized column whose value will be supplied dynamically, and specifies an alias for the customized column.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlQueryBuilderExamples
    {
        public class SelectRawExample
        {
            private SchoolContext _context;
    
            public SelectRawExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example2()
            {
    
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlQueryBuilder();
    
                // Defines a SQL statement, sets a customized column of int type, 
                // and sets its alias as "DefCol".
                sqlbuilder.Select("name")
                    .Select("budget")
                    .SelectRaw("selected = @a","DefCol",SqlBuilder.Parameter<int>("a"))
                    .From("Department");
    
                // Converts to raw SQL for the database corresponding to the data context.
                string sql = sqlbuilder.ToSqlString(_context);
    
                Console.WriteLine(sql);
                
                /*This code produces the following output:
                
                SELECT
                [name],
                [budget],
                [selected] = @a
                FROM [Department]
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon