SqlBuilder.Where(string left, ISqlParameter parameter) Method

    .NET Standard 2.x

    Creates an ISqlWhereCondition object which represents a search condition that can be used 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. The operator is '='.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

     public static ISqlWhereCondition Where(string left, ISqlParameter parameter);
    

    Parameters

    left System.String

    A SQL expression on the left of the operator.

    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.

    Examples

    The following code example uses the Where method to specify the column value to equal to an input parameter.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.SqlBuilderExamples
    {
        public class WhereExample
        {
            private SchoolContext _context;
    
            public WhereExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example3()
            {
                var sqlquerybuilder = new SqlQueryBuilder();
    
                // Defines a WHERE condition.
                var where =
                    SqlBuilder.Where("DepartmentID", 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