Show / Hide Table of Contents

    SqlBuilder.EmbeddedWhere(string left, SqlBinaryOperator sqlOperator, ISqlParameter parameter) Method

    .NET Standard 2.x

    Creates an ISqlWhereCondition object which represents a search condition that can be used (enclosed in parentheses) when building the WHERE clause. Specifies a SQL expression on the left of the operator and a SQL parameter on the right of the operator.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

     public static ISqlWhereCondition EmbeddedWhere(string left, SqlBinaryOperator sqlOperator, ISqlParameter parameter);
    

    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.

    parameter SnapObjects.Data.ISqlParameter

    An ISqlParameter object which represents a SQL parameter.

    It can be created by calling the SqlBuilder.Parameter method.

    Returns

    SnapObjects.Data.ISqlWhereCondition

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

    Remarks

    The newly created search condition is enclosed in parentheses. If the returned ISqlWhereCondition object is used to add another search condition, both of these search conditions will be enclosed in the same pair of parentheses.

    Examples

    The following code example demonstrates how to use the EmbeddedWhere method to specify the WHERE condition.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.SqlBuilderExamples
    {
        public class EmbeddedWhereExample
        {
            private SchoolContext _context;
    
            public EmbeddedWhereExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example4()
            {
                var sqlquerybuilder = new SqlQueryBuilder();
    
                // Defines an embedded WHERE condition.
                var where = SqlBuilder
                    .EmbeddedWhere("DepartmentID",
                                    SqlBinaryOperator.Equals,
                                    SqlBuilder.Parameter<int>("id"));
    
                // Creates a SQL statement.
                var query = sqlquerybuilder
                    .Select("*")
                    .From("Department")
                    .Where(where);
    
                // Converts to raw SQL for the database corresponding to the data context.
                string sql = query.ToSqlString(_context);
    
                Console.WriteLine(sql);
                
                /*This code example produces the following output:           
    
                SELECT
                *
                FROM [Department]
                WHERE ([DepartmentID] = @id)
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon