Show / Hide Table of Contents

    ISqlFromBuilder.From(string table, string alias) Method

    .NET Standard 2.x

    Adds a table or view (with the alias specified) to the FROM clause of the current object.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlFromBuilder From(string table, string alias);
    

    Parameters

    table System.String

    The name of the table or view.

    alias System.String

    The alias of the table or view.

    Returns

    SnapObjects.Data.ISqlFromBuilder

    Returns the current ISqlFromBuilder object.

    Examples

    The following code example demonstrates how to use the From(string table, string alias) method. It sets the alias of the "Department" table to "d", and retrieves all the records of the specified 3 columns.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlFromBuilderExamples
    {
        public class FromExample
        {
            private SchoolContext _context;
    
            public FromExample(SchoolContext dataContext)
            {
                // Sets the Data Context
                _context = dataContext;
            }
    
            public void Example3()
            {
    
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlQueryBuilder();
    
                // Builds a SQL statement to set the alias of the "Department" table to "d";
                // and retrieve all the records of the "name", "budget", and "startdate" columns from "Department".
                sqlbuilder.Select(new string[] { "d.name",
                    "d.budget",
                    "d.startdate" })
                    .From("Department", "d");
    
                // 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
                [d].[name],
                [d].[budget],
                [d].[startdate]
                FROM [Department] AS [d]    
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon