Show / Hide Table of Contents

    DynamicModel.SetValues(object[] values) Method

    .NET Standard 2.x

    Sets one or more values to the properties in the DynamicModel object according to the order of the property index.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    public void SetValues(object[] values)
    

    Parameters

    values System.Object[]

    One or more values to set to the properties in the DynamicModel object.

    Examples

    The following code example sets two property values according to the index in the DynamicModel object.

    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.DynamicModelExamples
    {
        public class SetValuesExample
        {
            private readonly SchoolContext _context;
    
            public SetValuesExample(SchoolContext dataContext)
            {
                // Sets the data context
                _context = dataContext;
            }
    
            public void Example()
            {
                string sql;
    
                sql = "select CourseID, Title from Course";
                DynamicModel dynamicModel =
                    _context.SqlExecutor.SelectOne<DynamicModel>(sql);
    
                // Shows the values in DynamicModel
                Console.WriteLine("Old Value:");
    
                var id = dynamicModel.GetValue(0);
                var title = dynamicModel.GetValue(1);
                Console.WriteLine("CourseID = {0}", id);
                Console.WriteLine("Title = {0}", title);
    
                // Sets new values in DynamicModel
                object[] values = new object[2];
    
                values[0] = 100;
                values[1] = "New Chemistry";
    
                dynamicModel.SetValues(values);
    
                // Shows the new values
                Console.WriteLine("New Value:");
    
                id = dynamicModel.GetValue(0);
                title = dynamicModel.GetValue(1);
                Console.WriteLine("CourseID = {0}", id);
                Console.WriteLine("Title = {0}", title);
    
                /* The code example produces the following output:
                
                Old Value:
                CourseID = 1045
                Title = Chemistry
                New Value:
                CourseID = 100
                Title = New Chemistry
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon