Show / Hide Table of Contents

    ISqlFromBuilder.GetTableAlias(string tableName) Method

    .NET Standard 2.x

    Gets the alias of a table source that has been added to the current object using the From or FromRaw method.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      string GetTableAlias(string tableName);
    

    Parameters

    tableName System.String

    The name of a table source that has been added to the current object.

    Returns

    System.String

    Returns the alias of the specified table source if the table source exists.

    Returns null if the table source does not exist.

    Examples

    The following code example demonstrates how to use the GetTableAlias(string tableName) method. It creates a SqlQueryBuilder object, and gets the alias of the "Department" table.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlFromBuilderExamples
    {
        public class GetTableAliasExample
        {
            private SchoolContext _context;
    
            public GetTableAliasExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example()
            {
    
                // Declares SqlQueryBuilder.            
    
                var sqlbuilder = new SqlQueryBuilder();
    
                // Defines a SQL statement to specify the alias of the "Department" table to "dept".
                sqlbuilder.Select("*")
                    .From("Department", "dept");
    
                // Converts to raw SQL for the database corresponding to the data context.
                string sql = sqlbuilder.ToSqlString(_context);
    
                Console.WriteLine(sql);
    
                // Shows the alias of the "Department" table.
                Console.WriteLine("The alias of the Department table: {0}",
                                  sqlbuilder.GetTableAlias("Department"));
    
                /*This code produces the following output:
                
                SELECT
                *
                FROM [Department] AS [dept]
                The alias of the Department table: dept       
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon