Show / Hide Table of Contents

    ISqlQueryBuilder.Select(string column, string alias) Method

    .NET Standard 2.x

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

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlQueryBuilder Select(string column, string alias);
    

    Parameters

    column System.String

    The column name to be added to the select list of a SELECT clause.

    alias System.String

    The alias of the column.

    Returns

    SnapObjects.Data.ISqlQueryBuilder

    Returns the current ISqlQueryBuilder object.

    Examples

    The following code example demonstrates how to use the Select(string column, string alias) method to select a column for the SELECT statement; the Select method can only choose one column at a time and can set an alias for the selected column.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlQueryBuilderExamples
    {
        public class SelectExample
        {
            private SchoolContext _context;
    
            public SelectExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example5()
            {
    
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlQueryBuilder();
    
                // Retrieves the Name and Budget values from Department table
                // Specifies "bg" as the alias for "budget" column and "nm" as the alias for "name" column.
                sqlbuilder.Select("budget", "bg")
                    .Select("name","nm")
                    .From("Department", "dept");
    
                // 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
                [budget] AS [bg],
                [name] AS [nm]
                FROM [Department] AS [dept]
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon