Show / Hide Table of Contents

    ISqlQueryBuilder.ReplaceSelect(string selectRaw) Method

    .NET Standard 2.x

    Replaces the select list in the SELECT clause with the specified raw SQL.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlQueryBuilder ReplaceSelect(string selectRaw);
    

    Parameters

    selectRaw System.String

    The raw SQL which will replace the select list in the SELECT clause.

    Returns

    SnapObjects.Data.ISqlQueryBuilder

    Returns the current ISqlQueryBuilder object.

    Examples

    The following code example demonstrates how to use the ReplaceSelect(string selectRaw) method to replace the columns in sqlbuilder with the columns specified by selectRaw.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlQueryBuilderExamples
    {
        public class ReplaceSelectExample
        {
            private SchoolContext _context;
    
            public ReplaceSelectExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example()
            {
    
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlQueryBuilder();
    
                // Selects all the columns from the "Department" table.
                sqlbuilder.Select("*")
                    .From("Department", "dept");
    
                Console.WriteLine("Before ReplaceSelect: {0}",
                                  sqlbuilder.ToSqlString(_context));
    
                // Replaces the columns in sqlbuilder with name, budget, and startdate columns.
                sqlbuilder.ReplaceSelect("name, budget, startdate");
    
                // Converts to raw SQL for the database corresponding to the data context.
                string sql = sqlbuilder.ToSqlString(_context);
    
                Console.WriteLine("After ReplaceSelect: {0}",
                                  sqlbuilder.ToSqlString(_context));
    
                /*This code produces the following output:
                
                Before ReplaceSelect: SELECT
                *
                FROM [Department] AS [dept]
    
                After ReplaceSelect: SELECT
                [name],
                [budget],
                [startdate]
                FROM [Department] AS [dept]
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon