Show / Hide Table of Contents

    ISqlModelMapper.GetQueryBuilder<TModel>(bool removeWhereClause = false) Method

    .NET Standard 2.x

    Gets the query conditions of a dynamic query.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    IQueryBuilder<TModel> GetQueryBuilder<TModel>(bool removeWhereClause = false)
    

    Type Parameters

    TModel

    The type of a model class.

    Parameters

    removeWhereClause System.Boolean

    A bool value that specifies whether to remove the WHERE clause from the SQL query.

    The default value is false.

    Returns

    SnapObjects.Data.IQueryBuilder<TModel>

    Returns a newly created IQueryBuilder object.

    Remarks

    You can add other query conditions to the result from this method. For example, you can add a WHERE clause as follows:

    var builder = _context.SqlModelMapper.GetQueryBuilder<Department>();
    builder.Where("DepartmentID", "1");
    

    Examples

    The following code example demonstrates how to use the GetQueryBuilder method.

    using System;
    using System.Threading;
    using System.Threading.Tasks;
    using Appeon.ApiDoc.Models.School;
    
    namespace Appeon.ApiDoc.ISqlModelMapperExamples
    {
        public class GetQueryBuilderExample
        {
            private readonly SchoolContext _context;
            
            public GetQueryBuilderExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public async Task<int> Example() 
            {
                // Get a QueryBuilder.
                var builder = _context.SqlModelMapper.GetQueryBuilder<Department>();
                
                // Add a where clause.
                builder.Where("DepartmentID", "1");
                
                var result = (await builder.LoadAsync()).ToList();
                
                foreach (var dept in result)
                {
                    Console.WriteLine("DepartmentID:    {0}", dept.DepartmentID);
                    Console.WriteLine("Name:            {0}", dept.Name);
                    Console.WriteLine("Budget:          {0}", dept.Budget);
                }
                
                return result.Count;
                
                /*This code example produces the following output:   
                
                    DepartmentID:    1
                    Name:            Engineering
                    Budget:          220000.0000
                    
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon