Show / Hide Table of Contents

    ISqlJoinBuilder.AsWhere() Method

    .NET Standard 2.x

    Returns an ISqlWhereAndOr object which Represents an object used to build the WHERE clause in a SQL statement.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlWhereAndOr AsWhere();
    

    Returns

    SnapObjects.Data.ISqlWhereAndOr

    Returns the ISqlWhereAndOr object which can be used to build the WHERE clause in a SQL statement (e.g. adding search conditions to the WHERE clause).

    Examples

    The following code example demonstrates how to use the AsWhere method to get the existing WHERE condition and add a condition to it.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlJoinBuilderExamples
    {
        public class AsWhereExample
        {
            private readonly SchoolContext _context;
    
            public AsWhereExample(SchoolContext dataContext)
            {
                // Sets data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                var sqlQueryBuilder = new SqlQueryBuilder();
    
                // Defines a SQL statement to query the DepartmentID and Name values from the Department table 
                // and specifies the WHERE condition to "DepartmentID < 5".
                sqlQueryBuilder
                    .Select("DepartmentID")
                    .Select("Name")
                    .From("Department")
                    .WhereRaw("DepartmentID < 5");
    
                // Gets the current WHERE condition and adds a new condition: DepartmentID > 1.
                sqlQueryBuilder.AsWhere().AndWhereRaw("DepartmentID > 1");
    
                // Converts to raw SQL for the database corresponding to the data context.
                string sql = sqlQueryBuilder.ToSqlString(_context);
    
                Console.WriteLine(sql);
    
                /*This code example produces the following output:           
                   SELECT
                    [DepartmentID],
                    [Name]
                   FROM[Department]
                   WHERE([DepartmentID] < 5
                         AND[DepartmentID] > 1)
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon