Show / Hide Table of Contents

    ILoadable.Include(Expression<Func<TModel, object>> property, bool cascade = false) Method

    .NET Standard 2.x

    Loads data for the specified embedded property 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

      ILoadable<TModel> Include(Expression<Func<TModel, object>> property, bool cascade = false);
    

    Parameters

    property System.Linq.Expressions.Expression<Func<TModel, object>>

    An embedded property of TModel class.

    This property is specified by an expression.

    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 the embedded properties in the detail model or the 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 specified embedded property, rather than loading data for all properties. This can greatly improve the data retrieval efficiency.

    Examples

    The following code example demonstrates how to load all of the departments and the courses for each department.

    using Appeon.ApiDoc.Models.School;
    using System;
    
    namespace Appeon.ApiDoc.ILoadableExamples
    {
        public class IncludeExample
        {
            private SchoolContext _context;
    
            public IncludeExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example1()
            {
                var mapper = _context.SqlModelMapper;
    
                // Loads the information of all departments and loads courses for 
                // each department.
                var depts = mapper.Load<DepartmentInfo>()
                                    .Include(o => o.Courses)
                                    .ToList();
    
                Console.WriteLine("The first department: {0}",
                    depts[0].Name);
                Console.WriteLine("Courses:");
                foreach (CourseInfo course in depts[0].Courses)
                {
                    Console.WriteLine(course.Title);
                }
    
                Console.WriteLine();
                Console.WriteLine("The second department: {0}",
                    depts[1].Name);
                Console.WriteLine("Courses:");
                foreach (CourseInfo course in depts[1].Courses)
                {
                    Console.WriteLine(course.Title);
                }
    
                /* The code produces the following output:
    
                The first department: Engineering
                Courses:
                Chemistry
                Physics
    
                The second department: English
                Courses:
                Composition
                Poetry
                Literature
                */
            }
        }
    }
    

    Example Refer To

    Model Classes: DepartmentInfo CourseInfo CourseStudentInfo

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon