Show / Hide Table of Contents

    DynamicModel.GetValue<TValue>(string columnName) Method

    .NET Standard 2.x

    Gets the value of the specified property (by name) in the DynamicModel object, and casts it to the specified data type.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    public TValue GetValue<TValue>(string columnName)
    

    Type Parameters

    TValue

    The data type of the value you want to get from the specified property.

    Parameters

    columnName System.String

    The name of the property to get value.

    Returns

    TValue

    Returns the value of the specified property.

    Examples

    The following code example gets the value according to the property name in the DynamicModel object and converts it to the specified data type.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.DynamicModelExamples
    {
        public class GetValueExample
        {
            private readonly SchoolContext _context;
    
            public GetValueExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example4()
            {
                string sql;
    
                sql = "select * from Course";
                DynamicModel dynamicModel =
                    _context.SqlExecutor.SelectOne<DynamicModel>(sql);
    
                // Gets the value of the "Title" property
                string value = dynamicModel.GetValue<string>("Title");
                Console.WriteLine("Value = {0}", value);
    
                /* The code example produces the following output:
                
                Value = Chemistry
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon