IDataUnpacker.GetModelEntries<TModel>([NotNull]this IDataUnpacker packer, [NotNull]string key) Method
.NET Standard 2.x
Gets the IEnumerable<IModelEntry<TModel>>
object created by the specified element.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public static IEnumerable<IModelEntry<TModel>> GetModelEntries<TModel>(
[NotNull]this IDataUnpacker packer,
[NotNull]string key) where TModel : class
Parameters
key
System.String
The key specifying which element will be used to create the IEnumerable<IModelEntry<TModel>>
object.
Returns
System.Collections.Generic.IEnumerable<IModelEntry<TModel>>
Returns the newly created IEnumerable<IModelEntry<TModel>>
object.
Remarks
If you are using a data format which has only data but no state for this element, the ModelState
property of every IModelEntry
object will be set to ModelState.NewModified
.
Examples
The following code example gets the IModelEntry
object in IDataUnPacker
object according to the key.
using Appeon.ApiDoc.Models.School;
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.IDataUnpackerExamples
{
public class GetModelEntriesExample
{
private readonly SchoolContext _context;
public GetModelEntriesExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example1(IDataUnpacker dataUnpacker)
{
// Gets the ModelEntries object according to the key value
var students = dataUnpacker.GetModelEntries<Person>("student");
// Shows the students.
foreach (var student in students)
{
Console.WriteLine("Model State: {0}",
student.ModelState);
Console.WriteLine("First Name: {0}",
student.GetCurrentValue("FirstName"));
Console.WriteLine("Last Name: {0}",
student.GetCurrentValue("LastName"));
Console.WriteLine();
}
/* This code example produces the following output:
Model State: NewModified
First Name: Lena
Last Name: Sherwood
Model State: NewModified
First Name: Davies
Last Name: Adam
*/
}
}
}
Example Refer To
Model Class: Person
Controller Class: GetModelEntriesExampleController
Applies to
.NET Standard
2.x