Show / Hide Table of Contents

    IEmbeddedLoadable.IncludeAllAsync(bool cascade = false, CancellationToken cancellationToken = default) Method

    .NET Standard 2.x

    Asynchronously loads all the embedded properties in TModel for all rows.

    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 model.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    Task<IEmbeddedLoadable<TModel>> IncludeAllAsync(bool cascade = false, CancellationToken cancellationToken = default);
    

    Parameters

    cascade System.Boolean

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

    The default value is false.

    cancellationToken CancellationToken

    A cancellation token that can be used by other objects or threads to receive notice of cancellation.

    Returns

    Task<IEmbeddedLoadable<TModel>>

    Returns a task that represents the asynchronous operation.

    Examples

    The following code example demonstrates how to load students and online flag asynchronously that belong to the Poetry course.

    using Appeon.ApiDoc.Models.School;
    using System;
    
    namespace Appeon.ApiDoc.IEmbeddedLoadableExamples
    {
        public class IncludeAllAsyncExample
        {
            private SchoolContext _context;
            
            public IncludeAllAsyncExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public async void Example()
            {
                var mapper = _context.SqlModelMapper;
                
                // Loads the course of Poetry (Course ID = 2030).
                var course = (await mapper.LoadByKeyAsync<CourseInfo>(2030)).FirstOrDefault();
                
                // Loads students and online flag.
                await mapper.LoadEmbedded(course).IncludeAllAsync();
                
                Console.WriteLine("Students who have selected the course of {0}:",
                   course.Title);
                   
                // Students.
                Console.WriteLine();
                foreach (CourseStudentInfo student in course.Students)
                {
                    Console.WriteLine("Course ID is {0}.",
                        student.CourseID);
                    Console.WriteLine("Student ID is {0}.",
                        student.StudentID);
                }
                
                // Online flag.
                Console.WriteLine();
                if (course.OnlineFlag == 1)
                {
                    Console.WriteLine("Online flag is True.");
                }
                else
                {
                    Console.WriteLine("Online flag is False.");
                }
                
                /*The code produces the following output is
                    
                    Students who have selected the course of Poetry:
        
                    Course ID is 2030.
                    Student ID is 2.
                    Course ID is 2030.
                    Student ID is 3.
        
                    Online flag is True.
                */
            }
        }
    }
    

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon