Show / Hide Table of Contents

    IDataIncludeGetter.Include<TKey>(string name, Expression<Func<TModel, TKey>> property) Method

    .NET Standard 2.x

    Gets the data of an embedded property of the TModel object from the IDataUnpacker object.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    IDataIncludeGetter<TModel> Include<TKey>(string name, Expression<Func<TModel, TKey>> property);
    

    Type Parameter

    TKey

    The type of the embedded property in the TModel object to be included.

    Parameters

    name System.String

    The name specified for the data.

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

    An Expression<Func<TModel,TKey>> object used to specify the embedded property in the TModel object to be included.

    Returns

    SnapObjects.Data.IDataIncludeGetter

    Returns the current IDataIncludeGetter object.

    Examples

    The following code example gets 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 IncludeExample
        {
            private readonly SchoolContext _context;
    
            public IncludeExample(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);
    
                var json = packer.GetTextString(DataFormat.Json);
    
                var dataUnPacker = new DataUnpacker(json, DataFormat.Json);
    
                // Gets the data including embedded data from the Model object of 
                // dataUnPacker according to the key value
                var list = dataUnPacker.GetModels<CourseInfo>(key)
                    .Include("Students", m => m.Students)
                    .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