Show / Hide Table of Contents

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

    .NET Standard 2.x

    Adds a raw SQL to the select list of a SELECT clause.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

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

    Parameters

    selectRaw System.String

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

    Actually, you can write any raw SQL if the SQL statement is valid.

    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 demonstrates how to use SelectRaw(string selectRaw, params ISqlParam[] parameters) to select columns in raw SQL, and select a customized column whose value will be supplied dynamically.

    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 Example1()
            {
    
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlQueryBuilder();
    
                // Defines a SQL statement, and sets a customized column of int type.
                sqlbuilder.SelectRaw("name, budget, selected = @a", 
                    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