Show / Hide Table of Contents

    ISqlWhereBuilder.Where(string left, SqlBinaryOperator sqlOperator, string right) Method

    .NET Standard 2.x

    Creates a WHERE clause, and adds a search condition to the WHERE clause. Specifies SQL expressions on both the left and right of the operator.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlWhereAndOr Where(string left, SqlBinaryOperator sqlOperator, string right);
    

    Parameters

    left System.String

    A SQL expression on the left of the operator.

    SqlBinaryOperator SnapObjects.Data.SqlBinaryOperator

    An enumeration value of SqlBinaryOperator, which is the operator to test the two expressions on the left and right.

    right System.String

    A SQL expression on the right of the operator.

    Returns

    SnapObjects.Data.ISqlWhereAndOr

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

    Examples

    The following code example uses the Where method to specify the column and the operator to associate multiple tables.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlWhereBuilderExamples
    {
        public class WhereExample
        {
            private readonly SchoolContext _context;
    
            public WhereExample(SchoolContext dataContext)
            {
                // Sets data context.
                _context = dataContext;
            }
    
            public void Example2()
            {
    
                // Declares SqlQueryBuilder.
                ISqlQueryBuilder sqlQueryBuilder = new SqlQueryBuilder();
    
                // Specifies columns to select.
                string[] columns = { "CourseID", "Title" };
    
                // Specifies to use the SqlBinaryOperator.Equals operator for matching the values.
                sqlQueryBuilder.Select(columns)
                                .From("Course", "a")
                                .From("Department", "b")
                                .Where("a.DepartmentID",
                                        SqlBinaryOperator.Equals,
                                        "b.DepartmentID");
    
                // Shows the SQL statement.
                Console.WriteLine("The SQL statement: \n{0}",
                                 sqlQueryBuilder.ToSqlString(_context));
    
                // Executes the SQL statement.
                var result =
                    _context.SqlExecutor.Select<DynamicModel>(sqlQueryBuilder);
    
                /*This code produces the following output:
    
                The SQL statement:
                SELECT
                 [CourseID],
                [Title]
                FROM [Course] AS [a] ,
                [Department] AS [b]
                WHERE ([a].[DepartmentID] = [b].[DepartmentID])
               */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon