Show / Hide Table of Contents

    IQueryAndOrBuilder<TModel>.OrWhereRaw(string clause, params ISqlParameter[] parameters) Method

    .NET Standard 2.x

    Adds the OR logical operator and a raw SQL to the WHERE clause.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      IQueryAndOrBuilder<TModel> OrWhereRaw(string clause, params ISqlParameter[] parameters);
    

    Parameters

    clause 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 define the SQL parameters used in the raw SQL.

    Returns

    IQueryAndOrBuilder<TModel>

    Returns anIQueryAndOrBuilder<TModel> object which can be used to add more search conditions to the current WHERE clause.

    Examples

    The following code example demonstrates how to use the OrWhereRaw method to add an OR condition (in raw SQL) to the WHERE clause.

    using Appeon.ApiDoc.Models.School;
    using SnapObjects.Data;
    using System;
    using System.Threading.Tasks;
    
    namespace Appeon.ApiDoc.IQueryAndOrBuilderExamples
    {
        public class OrWhereRawExample
        {
            private SchoolContext _context;
            
            public OrWhereRawExample(SchoolContext dataContext)
            {
                // Sets Data Context
                _context = dataContext;
            }
    
            public async Task<int> Example()
            {
                // Get a QueryBuilder.
                var Builder = _context.SqlModelMapper.GetQueryBuilder<Department>();
                
                Builder.WhereRaw("DepartmentID = :id", SqlBuilder.Parameter<int>("id"))
                       .OrWhereRaw("Name = :name", SqlBuilder.Parameter<string>("name"));
                
                var result = (await Builder.LoadAsync(4, "English")).ToList();
                
                foreach (var person in result)
                {
                    Console.WriteLine("DepartmentID:    {0}", person.DepartmentID);
                    Console.WriteLine("Name:            {0}", person.Name);
                    Console.WriteLine("Budget:          {0}", person.Budget);
                    Console.WriteLine("Administrator:   {0}", person.Administrator);
                    Console.WriteLine("StartDate:       {0}", person.StartDate);
                    Console.WriteLine();
                }
                
                return result.Count;
                
                /*This code example produces the following output:   
                
                    DepartmentID:    2
                    Name:            English
                    Budget:          120000.0000
                    Administrator:   6
                    StartDate:       9/1/2007 12:00:00 AM
                    
                    DepartmentID:    4
                    Name:            Economics
                    Budget:          200000.0000
                    Administrator:   4
                    StartDate:       9/1/2007 12:00:00 AM
                */
            }
        }
    }
    

    Example Refer To

    Model Class: Department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon