Show / Hide Table of Contents

    IDataUnpacker.GetModel<TModel>([NotNull]this IDataUnpacker packer, [NotNull]string key) Method

    .NET Standard 2.x

    Gets the model object created by the specified element.

    Namespace: SnapObjects.Data

    Assembly: SnapObjects.Data.dll

    Syntax

    public static IDataIncludeGetter<TModel> GetModel<TModel>(
    [NotNull]this IDataUnpacker packer,
    [NotNull]string key) where TModel : class
    

    Type Parameters

    TModel

    The type of the model object to create.

    Parameters

    key System.String

    The key specifying which element will be used to create the model object.

    Returns

    SnapObjects.Data.IDataIncludeGetter<TModel>

    Returns an IDataIncludeGetter<TModel> object which can be used to indicate which embedded property of TModel should be included.

    Examples

    The following code example gets the Model object in IDataUnPacker object according to the key.

    using Appeon.ApiDoc.Models.School;
    using SnapObjects.Data;
    using System;
    
    namespace Appeon.ApiDoc.IDataUnpackerExamples
    {
        public class GetModelExample
        {
            private readonly SchoolContext _context;
    
            public GetModelExample(SchoolContext dataContext)
            {
                // Sets the data context.
                _context = dataContext;
            }
    
            public void Example(IDataUnpacker dataUnpacker)
            {
                // Gets the Model object according to the key value
                var student = dataUnpacker.GetModel<Person>("student").FirstOrDefault();
    
                Console.WriteLine("First Name: {0}",
                    student.FirstName);
                Console.WriteLine("Last Name: {0}",
                    student.LastName);
    
                /* This code example produces the following output:
                
                First Name: Lena
                Last Name: Sherwood
                */
            }
        }
    }
    

    Example Refer To

    Model Class: Person
    Controller Class: GetModelExampleController

    Applies to

    .NET Standard

    2.x

    Back to top Generated by Appeon