Show / Hide Table of Contents

    SqlQueryBuilder.SqlQueryBuilder(string name = "") Constructor

    .NET Standard 2.x

    Initializes a new instance of the SqlQueryBuilder class.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      public SqlQueryBuilder(string name = "");
    

    Parameters

    name System.String

    (Optional) The name for this SqlQueryBuilder object.

    Examples

    The following code example demonstrates how to create a SqlQueryBuilder object.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.SqlQueryBuilderExamples
    {
        public class SqlQueryBuilderExample
        {
            private readonly SchoolContext _context;
    
            public SqlQueryBuilderExample(SchoolContext dataContext)
            {
                // Sets data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                // Creates a SqlQueryBuilder object.
                ISqlQueryBuilder query = new SqlQueryBuilder();
    
                // Uses this object to build a SQL statement.
                query.Select("name")
                   .Select("budget")
                   .From("Department", "dept");
    
                // Outputs the generated SQL statement.
                string sql = query.ToSqlString(_context);
                Console.WriteLine(sql);
    
                /*This code produces the following output:
                
                SELECT
                [name],
                [budget]
                FROM [Department] AS [dept]
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon