Show / Hide Table of Contents

    ISqlWhereAndOr<TBuilder>.AndWhere(ISqlWhereCondition condition) Method

    .NET Standard 2.x

    Adds the AND logical operator and a search condition (specified by an ISqlWhereCondition object) to the WHERE clause.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      TBuilder AndWhere(ISqlWhereCondition condition);
    

    Parameters

    condition SnapObjects.Data.ISqlWhereCondition

    An ISqlWhereCondition which represents a search condition in the WHERE Clause.

    This object can be created by using the SqlBuilder.Where method and so on.

    Returns

    TBuilder

    Returns the TBuilder object which can be used to add more search conditions to the current WHERE clause.

    Examples

    The following code example demonstrates how to use the AndWhere method to add an AND condition to the WHERE clause. In this example, the AND condition is specified by the variable for another WHERE clause.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlWhereAndOrExamples
    {
        public class AndWhereExample
        {
            private readonly SchoolContext _context;
    
            public AndWhereExample(SchoolContext dataContext)
            {
                // Sets data context.
                _context = dataContext;
            }
    
            public void Example7()
            {
    
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlQueryBuilder();
    
                // Defines a WHERE clause whose value is specified by the ISqlWhereCondition object.
                var where = SqlBuilder
                    .Where("DepartmentID", SqlBuilder.Parameter<int>("id"));
    
                // Defines a SQL statement and adds an AND condition to WHERE clause.
                // The condition is specified by WHERE clause defined above.
                sqlbuilder.Select("Title")
                    .From("Course", "a")
                    .Where("CourseID", SqlBinaryOperator.GreaterThan,
                          SqlBuilder.Parameter<int>("courid"))
                   .AndWhere(where);
    
                string sql = sqlbuilder.ToSqlString(_context);
    
                Console.WriteLine(sql);
    
                /*This code produces the following output:
    
                SELECT
                [Title]
                FROM [Course] AS [a]
                WHERE ([CourseID] > @courid
                AND ([DepartmentID] = @id))
               */
    
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon