Show / Hide Table of Contents

    DataStorePackerExtensions.AddDataStore([NotNull]this IDataPacker dataPacker,[NotNull]string key,[NotNull]IDataStore value,[NotNull]bool format = false) Method

    .NET Standard 2.x

    Adds an IDataStore object as an element to the IDataPacker object.

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public static void AddDataStore(
          [NotNull]this IDataPacker dataPacker,
          [NotNull]string key,
          [NotNull]IDataStore value,
          [NotNull]bool format = false)
    

    Parameters

    dataPacker SnapObjects.Data.IDataPacker

    The IDataPacker object that can package multiple types of data element together.

    key System.String

    The key for the element, which is the identifier of the element in the IDataPacker object.

    value DWNet.Data.IDataStore

    An IDataStore object, which is the value of the element to be added to the IDataPacker object.

    format System.Boolean

    DataWindow column headings format.

    Examples

    The following code example adds a DataStore object as an element to the IDataPacker object and uses the DataStore name as the key name for the element and uses the DataWindow format.

    using SnapObjects.Data;
    using DWNet.Data;
    using System;
    using Appeon.ApiDoc.Models;
    
    namespace Appeon.ApiDoc.DataStorePackerExtensionsExamples
    {
        public class AddDataStoreExample
        {
            private readonly SchoolContext _context;
    
            public AddDataStoreExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example1()
            {
                // Instantiates a DataStore object with datawindow: d_department.
                var dataStore = new DataStore("d_department", _context);
    
                dataStore.Retrieve();
    
                var dataPacker = new DataPacker();
    
                // Adds the DataStore object as an element to the current IDataPacker
                // and adds the DataStore name as the key name for the element
                // and uses the DataWindow format.
                var key = nameof(dataStore);
                dataPacker.AddDataStore(key, dataStore, true);
    
                // Gets all of the data in IDataPacker and shows the data in DataWindow format.
                string text = dataPacker.GetRaw(key);
                Console.WriteLine(text);
    
                /* This code example produces the following output:
                
                {"identity":"70c86603-983b-4bd9-adbc-259436e43cbd","version":1.0,"platform":"C#",
                "mapping-method":0,"dataobject":{"name":"d_department","meta-columns":[{"name":
                "Departmentid","index":0,"datatype":"System.Int32","nullable":0},{"name":"Name",
                "index":1,"datatype":"System.String","nullable":0},{"name":"Budget","index":2,
                "datatype":"System.Decimal","nullable":0},{"name":"Startdate","index":3,
                "datatype":"System.DateTime","nullable":0},{"name":"Administrator","index":4,
                "datatype":"System.Int32","nullable":1}],"primary-rows":[{"row-status":-1,
                "columns":{"Departmentid":[1],"Name":["Engineering"],"Budget":[220000.0000],
                "Startdate":["2007-09-01T00:00:00"],"Administrator":[2]}},{"row-status":-1,
                "columns":{"Departmentid":[2],"Name":["English"],"Budget":[120000.0000],
                "Startdate":["2007-09-01T00:00:00"],"Administrator":[6]}},{"row-status":-1,
                "columns":{"Departmentid":[4],"Name":["Economics"],"Budget":[200000.0000],
                "Startdate":["2007-09-01T00:00:00"],"Administrator":[4]}},{"row-status":-1,
                "columns":{"Departmentid":[7],"Name":["Mathematics"],"Budget":[250000.0000],
                "Startdate":["2007-09-01T00:00:00"],"Administrator":[3]}}],"filter-rows":[],
                "delete-rows":[],"dwchilds":{}}}
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon