Show / Hide Table of Contents

    DataStorePackerExtensions.GetModelEntries<TModel>([NotNull]this IDataPacker dataPacker,[NotNull]string key) Method

    .NET Standard 2.x

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

    Namespace: DWNet.Data

    Assembly: DWNet.Data.dll

    Syntax

      public static IEnumerable<IModelEntry<TModel>> GetModelEntries<TModel>(
          [NotNull]this IDataPacker dataPacker,
          [NotNull]string key) where TModel : class
    

    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.

    Returns

    IEnumerable<IModelEntry<TModel>>

    Returns the newly created IEnumerable<IModelEntry<TModel>> object.

    Examples

    The following code example demonstrates how to get an IEnumerable<IModelEntry<TModel>> object from IDataPacker according to a key.

    using Appeon.ApiDoc.Models;
    using DWNet.Data;
    using SnapObjects.Data;
    using System;
    using System.Linq;
    
    namespace Appeon.ApiDoc.DataStorePackerExtensionsExamples
    {
        public class GetModelEntriesExample
        {
            private readonly SchoolContext _context;
    
            public GetModelEntriesExample(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 an `IEnumerable<IModelEntry<TModel>>` object from dataUnPacker 
                // according to the key.
                var entries = dataPacker.GetModelEntries<D_Department>(key);
    
                Console.WriteLine("GetModelEntries Count: {0}", entries.Count());
    
                /* This code example produces the following output:
                
                GetModelEntries Count: 4
                */
            }
        }
    }
    

    Example Refer To

    Model Class: D_Department
    DataWindow File: d_department

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon