Show / Hide Table of Contents

    IDataIncludeGetter.IncludeAll() Method

    .NET Standard 2.x

    Gets the data of all embedded properties of the TModel object from the IDataUnpacker object.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    IDataIncludeGetter<TModel> IncludeAll();
    

    Returns

    SnapObjects.Data.IDataIncludeGetter

    Returns the current IDataIncludeGetter object.

    Examples

    The following code example gets all of the embedded data from the TModel object of IDataUnpacker.

    using Appeon.ApiDoc.Models.School;
    using SnapObjects.Data;
    using System;
    using System.Collections.Generic;
    
    namespace Appeon.ApiDoc.IDataIncludeGetterExamples
    {
        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)
                    .Include("Students", m => m.Students)
                    .Include("Instructors", m => m.Instructors);
    
                var json = packer.GetTextString(DataFormat.Json);
    
                var dataUnPacker = new DataUnpacker(json, DataFormat.Json);
    
                // Gets the data including all of the embedded data from the Model object of 
                // dataUnPacker according to the key value.
                var list = dataUnPacker.GetModels<CourseInfo>(key)
                    .IncludeAll()
                    .ToList(); 
    
                // Gets and shows the total records of embedded data
                Console.WriteLine("The count is: {0}",
                      list[0].Students.Count.ToString());
    
                /* This code example produces the following output:
                
                The count is: 5
                */
            }
        }
    }
    

    Example Refer To

    Model Class: CourseInfo

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon