Show / Hide Table of Contents

    DataStorePackerExtensions.AddModelEntries<TModel>([NotNull]this IDataPacker dataPacker,[NotNull]string key,[NotNull]IEnumerable<IModelEntry<TModel>> modelEntries) Method

    .NET Standard 2.x

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

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public static void AddModelEntries<TModel>(
          [NotNull]this IDataPacker dataPacker,
          [NotNull]string key,
          [NotNull]IEnumerable<IModelEntry<TModel>> modelEntries)
    

    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.

    modelEntries IEnumerable<IModelEntry<TModel>>

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

    Examples

    The following code example adds an IEnumerable<IModelEntry<TModel>> objectas an element to the IDataPacker object.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using SnapObjects.Data;
    using System;
    using System.Linq;
    
    namespace Appeon.ApiDoc.DataStorePackerExtensionsExamples
    {
        public class AddModelEntriesExample
        {
            private readonly SchoolContext _context;
    
            public AddModelEntriesExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                // 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 an `IEnumerable<IModelEntry<TModel>>` object as an element to the 
                // `IDataPacker` object.
                var entries = dataPacker.GetModelEntries<D_Department>(key);
    
                Console.WriteLine("GetModelEntries Count: {0}", entries.Count());
    
                var newPacker = new DataPacker();
                newPacker.AddModelEntries(key, entries);
    
                // Gets all of the data in IDataPacker and shows the data in JSON format.
                string text = newPacker.GetTextString(DataFormat.Json);
                Console.WriteLine(text);
    
                /* This code example produces the following output:
                
                GetModelEntries Count: 4
    
                {"dataStore":{"identity":"6476d6ed-1e62-4441-a5bb-9a6ac62d0256","version":1.0,
                "platform":"C#","mapping-method":0,"modelstore":{"name":"Appeon.ApiDoc.Models.
                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}],
                "rows":[{"row-status":-1,"columns":{"Departmentid":[1],"Name":["Engineering"],
                "Budget":[220000.0],"Startdate":["2007-09-01T00:00:00"],"Administrator":[2]}},
                {"row-status":-1,"columns":{"Departmentid":[2],"Name":["English"],"Budget":
                [120000.0],"Startdate":["2007-09-01T00:00:00"],"Administrator":[6]}},
                {"row-status":-1,"columns":{"Departmentid":[4],"Name":["Economics"],"Budget":
                [200000.0],"Startdate":["2007-09-01T00:00:00"],"Administrator":[4]}},
                {"row-status":-1,"columns":{"Departmentid":[7],"Name":["Mathematics"],"Budget":
                [250000.0],"Startdate":["2007-09-01T00:00:00"],"Administrator":[3]}}]}}}
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon