Show / Hide Table of Contents

    ILoadable.IncludeAll(int index, bool cascade = false); Method

    .NET Standard 2.x

    Loads data for the embedded properties (where the ModelEmbedded attribute or the SqlEmbedded attribute is applied) in TModel for the specified row.

    If the ModelEmbedded attribute is applied in the property, the property will use the SQL query (defined in the detail model class specified by the ModelType property of the ModelEmbedded attribute) to retrieve data from database. The cascade parameter can be used to decide whether to retrieve data for the embedded properties in the detail model or the granddetail mode.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

      ILoadable<TModel> IncludeAll(int index, bool cascade = false);
    

    Parameters

    index System.Int32

    The zero-based index for the row in the result set.

    cascade System.Boolean

    Only when the ModelEmbedded attribute is applied in the property, the cascade parameter can be used to decide whether to retrieve data for embedded properties in the detail model or granddetail model. See master-detail-granddetail for more info.

    The default value is false.

    Returns

    SnapObjects.Data.ILoadable<TModel>

    Returns the current ILoadable<TModel> object whose methods can be used to further obtain the data result set or perform data operations such as embedded queries.

    Remarks

    The ILoadable.Include method can be used to load the data for the embedded properties (where the ModelEmbedded attribute or the SqlEmbedded attribute is applied) for the specified row, rather than loading data for all rows. This can greatly improve the data retrieval efficiency.

    Examples

    The following code example demonstrates how to load all of the courses for the English department and the details about the Poetry course.

    using Appeon.ApiDoc.Models.School;
    using System;
    
    namespace Appeon.ApiDoc.ILoadableExamples
    {
        public class IncludeAllExample
        {
            private SchoolContext _context;
    
            public IncludeAllExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example2()
            {
                var mapper = _context.SqlModelMapper;
    
                // Loads all courses for the English department 
                // (DepartmentID = 2).
                var loadable = mapper.Load<CourseInfo>(2);
    
                // Gets the index of the English department.
                int poetryIndex = loadable.ToList().FindIndex(o => o.Title == "Poetry");
    
                // Loads details of the Poetry course only.
                var courses = loadable.IncludeAll(poetryIndex, cascade: true)
                                    .ToList();
    
                Console.WriteLine("Courses: {0}",
                    courses[poetryIndex].Title);
    
                // Students of the Poetry course.
                Console.WriteLine();
                Console.WriteLine("Student IDs:");
                foreach (CourseStudentInfo student in courses[poetryIndex].Students)
                {
                    Console.WriteLine(student.StudentID);
                }
    
                // Instructors of the Poetry course.
                Console.WriteLine();
                Console.WriteLine("Instructor ID(s):");
                foreach (
                    CourseInstructorInfo instructor in courses[poetryIndex].Instructors)
                {
                    Console.WriteLine(instructor.PersonID);
                }
    
                /* The code produces the following output:
    
                Courses: Poetry
    
                Student IDs:
                2
                3
    
                Instructor ID(s):
                4
                */
            }
        }
    }
    

    Example Refer To

    Model Classes: CourseInfo CourseStudentInfo CourseInstructorInfo

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon