Show / Hide Table of Contents

    SqlBuilder.EmbeddedWhereRaw(string clause, string whereName, params ISqlParameter[] parameters) 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. This search condition is specified by a raw SQL string. You need to specify a name for the raw SQL.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

     public static ISqlWhereCondition EmbeddedWhereRaw(string clause, string whereName, params ISqlParameter[] parameters);
    

    Parameters

    clause System.String

    A string of raw SQL to be added to the WHERE clause.

    whereName System.String

    The name for the raw SQL. It can be used to remove the raw SQL from the WHERE clause.

    parameters Appeon.CoreService.ISqlParameter[]

    (Optional) An array of ISqlParameter objects which defines the SQL parameters used in the raw SQL.

    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 EmbeddedWhereRaw method to specify a WHERE condition in a raw SQL string.

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