Show / Hide Table of Contents

    ISqlBuilder.ToReadOnly() Method

    .NET Standard 2.x

    Gets a read-only ISqlReadOnlyBuilder object generated by the clone of the current object.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlReadOnlyBuilder ToReadOnly();
    

    Returns

    SnapObjects.Data.ISqlReadOnlyBuilder

    A read-only ISqlReadOnlyBuilder object which can generate the same SQL statements as the current object.

    Examples

    The following code example demonstrates how to get a read-only ISqlReadOnlyBuilder object.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlBuilderExamples
    {
        public class ToReadOnlyExample
        {
            private SchoolContext _context;
    
            public ToReadOnlyExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example()
            {
                // Builds a SQL statement.
                var sqlBuilder = new SqlQueryBuilder();
                sqlBuilder.Select("name")
                        .From("Department")
                        .WhereValue("DepartmentId", 1);
    
                // You cannot set any properties or continue to build the SQL statement 
                // after using the ToReadOnly method. 
                var readonlySqlBuilder = sqlBuilder.ToReadOnly();
    
                // Gets the SQL statement.
                string sql = readonlySqlBuilder.ToSqlString(_context);
    
                Console.WriteLine("The SQL SELECT statement: \n{0}", sql);
    
                /*This code produces the following output:
                
                The SQL SELECT statement:
                SELECT
                 [name]
                FROM [Department]
                WHERE ([DepartmentId] = 1)         
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon