Show / Hide Table of Contents

    ISqlWhereBuilder.WhereRaw(string whereClause, params ISqlParameter[] parameters) Method

    .NET Standard 2.x

    Creates a WHERE clause, and adds a raw SQL to the WHERE clause.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ISqlWhereAndOr WhereRaw(string whereClause, params ISqlParameter[] parameters);
    

    Parameters

    whereClause System.String

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

    parameters SnapObjects.Data.ISqlParameter[]

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

    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 WhereRaw method to build the WHERE condition in a raw SQL.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.ISqlWhereBuilderExamples
    {
        public class WhereRawExample
        {
            private readonly SchoolContext _context;
    
            public WhereRawExample(SchoolContext dataContext)
            {
                // Sets data context.
                _context = dataContext;
            }
    
            public void Example1()
            {
    
                // Declares SqlQueryBuilder.
                var sqlbuilder = new SqlQueryBuilder();
    
                // Defines a SQL statement, and specifies the WHERE condition in a raw SQL: Title = @titlename.
                sqlbuilder.Select("*")
                    .From("Course")
                    .WhereRaw("Title = @titlename", 
                               SqlBuilder.Parameter<string>("titlename"));
    
                string sql = sqlbuilder.ToSqlString(_context);
    
                Console.WriteLine(sql);
    
                /*This code produces the following output:
    
                SELECT
                *
                FROM [Course]
                WHERE ([Title] = @titlename)
               */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon