IDataIncludeGetter.ToList() Method
.NET Standard 2.x
Creates an IList <TModel>
object which contains the data from the IDataUnpacker object.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
IList<TModel> ToList();
Returns
System.Collections.Generic.IList<TModel>
An IList <TModel>
object containing the data from the IDataUnpacker object.
Examples
The following code example adds all of the data from IDataUnpacker
to a list.
using Appeon.ApiDoc.Models.School;
using SnapObjects.Data;
using System;
using System.Collections.Generic;
namespace Appeon.ApiDoc.IDataIncludeGetterExamples
{
public class ToListExample
{
private readonly SchoolContext _context;
public ToListExample(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)
.IncludeAll();
var json = packer.GetTextString(DataFormat.Json);
var dataUnPacker = new DataUnpacker(json, DataFormat.Json);
// Gets the data from the Model object of dataUnPacker according
// to the key value, and converts to a list
var list = dataUnPacker.GetModels<CourseInfo>(key).ToList();
// Gets and shows the total number of records in the list
Console.WriteLine("The count is: {0}",
list.Count.ToString());
/* This code example produces the following output:
The count is: 3
*/
}
}
}
Example Refer To
Model Class: CourseInfo
Applies to
.NET Standard
2.x