Show / Hide Table of Contents

    SqlExecutorExtensions.SelectToStore<TModel>(this ISqlExecutor sqlExecutor, ISqlQueryBuilder queryBuilder, params object[] parameters) Method

    .NET Standard 2.x

    (Obsolete) Executes the SQL SELECT statement generated by an ISqlQueryBuilder object and returns an IModelStore<TModel> object which contains the result set.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

    public static IModelStore<TModel> SelectToStore<TModel>(this ISqlExecutor sqlExecutor, ISqlQueryBuilder queryBuilder, params object[] parameters)
    

    Type Parameters

    TModel

    The datatype of the model object which represents the data row in the result set.

    You can also specify DynamicModel to TModel if you do not want to define a custom model class.

    Parameters

    sqlExecutor SnapObjects.Data.ISqlExecutor

    An ISqlExecutor that can run SQL statements.

    queryBuilder SnapObjects.Data.ISqlQueryBuilder

    A SqlQueryBuilder object which can be used to generate a SQL SELECT statement.

    parameters System.Object[]

    (Optional) One or more ParamValue objects which contain the values corresponding to the SQL parameter identifier names.

    You can also pass the arguments directly in the order in which they appear in the SQL SELECT statement generated by sqlQueryBuilder without using the ParamValue object.

    Returns

    DWNet.Data.IModelStore<TModel>

    Returns an IModelStore<TModel> object which contains the result set.

    Examples

    The following code example demonstrates how to use the SelectToStore<TModel>(ISqlQueryBuilder, params Object[] method to generate and execute the SQL statement using a SqlQueryBuilder and place the query result to a ModelStore.

    using Appeon.ApiDoc.Models.School;
    using DWNet.Data;
    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.SqlExecutorExtensionsExamples
    {
        public class SelectToStoreExample
        {
            private readonly SchoolContext _context;
    
            public SelectToStoreExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example3()
            {
                // Creates SqlQueryBuilder.
                var builder = new SqlQueryBuilder();
    
                // Defines the SQL statement.
                builder.Select("CourseID")
                       .Select("Title")
                       .From("Course");
    
                // Executes the SQL statement and puts the query result to a ModelStore.
                var ms = _context.SqlExecutor.Select<DynamicModel>(builder);
    
                Console.WriteLine("Records Count: {0}.", ms.Count);
    
                /*This code produces the following output:
    
                Records Count: 10.
                */
            }
        }
    }
    

    Example Refer To

    Model Class: Course

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon