Show / Hide Table of Contents

    ISqlFromBuilder.From(string table, string alias, string schema) Method

    .NET Standard 2.x

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

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlFromBuilder From(string table, string alias, string schema);
    

    Parameters

    table System.String

    The name of the table or view.

    alias System.String

    The alias of the table or view.

    schema System.String

    The schema 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, string schema) method. It sets the alias of the "Department" table to "d", specifies the schema, and retrieves all the records of the "name", "budget", and "startdate" columns from the "Department" table.

    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 Example4()
            {
    
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlQueryBuilder();
    
                // Builds a SQL statement to set the alias of the "Department" table to "d", specify the schema to "dbo",
                // 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", "dbo");
    
                // 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 [dbo].[Department] AS [d] 
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon