Show / Hide Table of Contents

    IQueryWhereBuilder.Where(string left, SqlBinaryOperator sqlOperator, string right) Method

    .NET Standard 2.x

    Creates a WHERE clause, and adds a search condition to the WHERE clause. Specifies SQL expressions on both the left and right of the operator.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    IQueryAndOrBuilder<TModel> Where(string left, SqlBinaryOperator sqlOperator, string right);
    

    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.

    right System.String

    A SQL expression on the right of the operator.

    Returns

    IQueryAndOrBuilder<TModel>

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

    Examples

    The following code example uses the Where method to specify the column and the operator.

    using Appeon.ApiDoc.Models.School;
    using SnapObjects.Data;
    using System;
    using System.Threading.Tasks;
    
    namespace Appeon.ApiDoc.IQueryWhereBuilderExamples
    {
        public class WhereExample
        {
            private SchoolContext _context;
            
            public WhereExample(SchoolContext dataContext)
            {
                // Sets Data Context
                _context = dataContext;
            }
    
            public async Task<int> Example2()
            {
                // Get a QueryBuilder.
                var Builder = _context.SqlModelMapper.GetQueryBuilder<Person>();
                
                // Creates a WHERE clause, and adds a search condition to the WHERE clause. 
                // Specifies SQL expressions on both the left and right of the operator.
                Builder.Where("FirstName", SqlBinaryOperator.Equals, "LastName");
                
                var result = (await Builder.LoadAsync()).ToList();
                
                foreach (var person in result)
                {
                    Console.WriteLine("PersonID:    {0}", person.PersonID);
                    Console.WriteLine("FirstName:   {0}", person.FirstName);
                    Console.WriteLine("LastName:    {0}", person.LastName);
                    Console.WriteLine("HireDate:    {0}", person.HireDate);
                    Console.WriteLine("Discriminator:   {0}", person.Discriminator);
                }
                
                return result.Count;
                
                /*This code produces the following output:
                
                    PersonID:    3008
                    FirstName:   Vico
                    LastName:    Vico
                    HireDate:
                    Discriminator:   Student
                */
            }
        }
    }
    

    Example Refer To

    Model Class: Person

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon