Show / Hide Table of Contents

    ISqlWhereAndOr<TBuilder>.OrWhere(ISqlWhereCondition condition) Method

    .NET Standard 2.x

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

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      TBuilder OrWhere(ISqlWhereCondition condition);
    

    Parameters

    condition SnapObjects.Data.ISqlJoinCondition

    An ISqlWhereCondition which represents a search condition for 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 OrWhere method to add an OR condition to the WHERE clause. In this example, the OR condition is specified by the variable for another WHERE clause.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlWhereAndOrExamples
    {
        public class OrWhereExample
        {
            private readonly SchoolContext _context;
    
            public OrWhereExample(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 OR 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"))
                   .OrWhere(where);
    
                string sql = sqlbuilder.ToSqlString(_context);
    
                Console.WriteLine(sql);
    
                /*This code produces the following output:
    
                SELECT
                [Title]
                FROM [Course] AS [a]
                WHERE ([CourseID] > @courid
                OR ([DepartmentID] = @id))
               */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon