Show / Hide Table of Contents

    IQueryWhereBuilder.Where(ISqlWhereCondition condition) Method

    .NET Standard 2.x

    Creates a WHERE clause, and adds a search condition to the WHERE clause by an ISqlWhereCondition object.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    IQueryAndOrBuilder<TModel> Where(ISqlWhereCondition condition);
    

    Parameters

    condition SnapObjects.Data.ISqlWhereCondition

    An ISqlWhereCondition which represents a search condition in the WHERE clause.

    This object can be created by using the SqlBuilder.Where method and so on.

    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 declares an ISqlWhereCondition object, uses it in the Where method, and specifies an alias for it.

    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> Example7()
            {
                // Get a QueryBuilder.
                var Builder = _context.SqlModelMapper.GetQueryBuilder<Person>();
                
                // Defines a SqlWhereCondition.
                var sqlwherebuilder = SqlBuilder.Where("PersonID",
                                                        SqlBuilder.Parameter<int>("id"));
                                                        
                // Creates a WHERE clause, and adds a search condition to the WHERE clause 
                // by an ISqlWhereCondition object.
                Builder.Where(sqlwherebuilder);
                
                var result = (await Builder.LoadAsync(1)).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:    1
                    FirstName:   Kim
                    LastName:    Abercrombie
                    HireDate:    3/11/1995 12:00:00 AM
                    Discriminator:   Instructor
                */
            }
        }
    }
    

    Example Refer To

    Model Class: Person

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon