Show / Hide Table of Contents

    IDataIncludeSetter.IncludeAll() Method

    .NET Standard 2.x

    Adds the data of all embedded properties of TModel object to the IDataPacker object.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    void IncludeAll();
    

    Remarks

    If you use IDataPacker.AddModel to add the data of a TModel object to the IDataPacker object and name it Key1, and then use the IDataIncludeSetter.IncludeAll method to add data of all embedded properties of the TModel object to the IDataPacker object, then the name will be combined to Key1.PropertyName for the data from each property, PropertyName is the name of the property.

    If you use IDataPacker.AddModels to add the data of a collection of TModel objects to the IDataPacker object and name it Key1, and then use the IDataIncludeSetter.IncludeAll method to add data of all embedded properties of the TModel object to the IDataPacker object, then the name will be combined to Key1[n].PropertyName for the data from each property. n is the zero-based index of a TModel object in its collection, and PropertyName is the name of the property.

    Examples

    The following code example packs the TModel object and all of the embedded data.

    using Appeon.ApiDoc.Models.School;
    using SnapObjects.Data;
    using System;
    using System.Collections.Generic;
    
    namespace Appeon.ApiDoc.IDataIncludeSetterExamples
    {
        public class IncludeAllExample
        {
            private readonly SchoolContext _context;
    
            public IncludeAllExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example()
            {
                var packer = new DataPacker();
    
                var mapper = new SqlModelMapper(_context);
    
                var items = mapper.Load<CourseInfo>(2).IncludeAll().ToList();
    
                // Adds the items object and the embedded data to packer.
                string key = "Models";
                packer.AddModels(key, items)
                      .IncludeAll();
    
                // Gets and shows the total number of records in packer
                Console.WriteLine("The count is: {0}",
                    packer.Count.ToString());
    
                // Gets and shows all of the key values of packer
                string keys = "";
                for (int i = 0; i < packer.Count; i++)
                {
                    keys = keys + packer.Keys[i] + ", ";
                }
                Console.WriteLine("The key values is: {0}", keys);
    
                /* This code example produces the following output:
                
                The count is: 10
                The key values is: Models, Models[0].Students, Models[1].Students, 
                Models[2].Students, Models[0].Instructors, Models[1].Instructors, 
                Models[2].Instructors, Models[0].OnlineFlag, Models[1].OnlineFlag, 
                Models[2].OnlineFlag,
                */
            }
        }
    }
    

    Example Refer To

    Model Class: CourseInfo

    Applies to

    .NET Standard

    2.x

    See Also

    IDataPacker.AddModel

    IDataPacker.AddModels

    Back to top Generated by Appeon