Show / Hide Table of Contents

    ISqlBuilderBase.UsedParameters Property

    .NET Standard 2.x

    Gets an IReadOnlyDictionary<string, ISqlParameter> object that contains all parameters used in the current object.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

       IReadOnlyDictionary<string, ISqlParameter> UsedParameters { get; }
    

    Returns

    System.Collections.Generic.IReadOnlyDictionary<System.String, SnapObjects.Data.ISqlParameter>

    Returns an IReadOnlyDictionary<string, ISqlParameter> object that contains all parameters.

    Examples

    The following code example demonstrates how to use the UsedParameters property.

    using SnapObjects.Data;
    using System;
    using System.Linq;
    
    namespace Appeon.ApiDoc.ISqlBuilderBaseExamples
    {
        public class UsedParametersExample
        {
            private SchoolContext _context;
    
            public UsedParametersExample(SchoolContext dataContext)
            {
                // Sets Data Context.
                _context = dataContext;
            }
    
            public void Example()
            {
                // Creates a SqlQueryBuilder object.
                var sqlQueryBuilder = new SqlQueryBuilder();
    
                // Adds a parameter.
                sqlQueryBuilder.AddParameters(SqlBuilder.Parameter<int>("deptID"));
    
                sqlQueryBuilder.Select("name")
                                .From("Department")
                                .Where("DepartmentId", "@deptID");
    
                // Uses Validate (or ToSqlString) method to generate the used parameters internally.
                sqlQueryBuilder.Validate(_context);
    
                // Gets the first parameter.
                var parameter = sqlQueryBuilder.UsedParameters.FirstOrDefault();
                Console.WriteLine("Name: {0}",
                   parameter.Key);
                Console.WriteLine("Direction: {0}",
                    parameter.Value.Direction);
                Console.WriteLine("Datatype: {0}",
                    parameter.Value.DataType.ToString());
    
                /*This code produces the following output:
                
                Name: deptID
                Direction: Input
                Datatype: System.Int32
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon