Show / Hide Table of Contents

    ISqlWhereAndOr<TBuilder>.OrWhereValue(string left, object value) Method

    .NET Standard 2.x

    Adds the OR logical operator and a search condition to the WHERE clause; and specifies a SQL expression on the left the operator and a specific value on the right of the operator. The operator is '='.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      TBuilder OrWhereValue(string left, object value);
    

    Parameters

    left System.String

    An expression on the left of the operator.

    value System.Object

    The specific value on the right of the operator.

    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 OrWhereValue method to add an OR condition to the WHERE clause. In this example, the OR condition specifies that the Title value must be equal to "Physics".

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlWhereAndOrExamples
    {
        public class OrWhereValueExample
        {
            private readonly SchoolContext _context;
    
            public OrWhereValueExample(SchoolContext dataContext)
            {
                // Sets data context.
                _context = dataContext;
            }
    
            public void Example1()
            {
    
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlQueryBuilder();
    
                // Defines a SQL statement and adds an OR condition to the WHERE clause: Title = "Physics".
                sqlbuilder.Select("*")
                    .From("Course")
                    .Where("CourseID", SqlBuilder.Parameter<int>("courid"))
                    .OrWhereValue("Title", "Physics");
    
                string sql = sqlbuilder.ToSqlString(_context);
    
                Console.WriteLine(sql);
    
                /*This code produces the following output:
    
                SELECT
                *
                FROM [Course]
                WHERE ([CourseID] = @courid
                OR [Title] = N'Physics')
               */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon