Show / Hide Table of Contents

    ISqlFromBuilder.From(ISqlBuilder sqlBuilder, string alias) Method

    .NET Standard 2.x

    Adds a derived table (specified by another ISqlBuilder object and an alias) to the FROM clause of the current object.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlFromBuilder From(ISqlBuilder sqlBuilder, string alias);
    

    Parameters

    sqlBuilder SnapObjects.Data.ISqlBuilder

    An ISqlBuilder object which represents a derived table.

    alias System.String

    The alias of the derived table.

    Returns

    SnapObjects.Data.ISqlFromBuilder

    Returns the current ISqlFromBuilder object.

    Examples

    The following code example demonstrates how to use the From(ISqlBuilder sqlBuilder, string alias) method. It creates a derived table by a subquery with the name "dept" and retrieves all the records from the derived 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 Example1()
            {
    
                // Declares SqlQueryBuilder.
                var subQuery = new SqlQueryBuilder();
                var sqlbuilder = new SqlQueryBuilder();
    
                // Creates a subquery to retrieve all the values of the "Name" column from the "department" table.
                subQuery.Select("Name")
                        .From("department");
    
                // Creates a subquery with the name "dept" and retrieves all the records.
                sqlbuilder.Select("*").From(subQuery, "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
                *
                FROM (SELECT
                [Name]
                FROM [department]) AS [dept]        
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon