IDataUnpacker.GetModelEntries<TModel>([NotNull]this IDataUnpacker packer, [NotNull]string key, [NotNull]MappingMethod mappingMethod) Method
.NET Standard 2.x
Gets the IEnumerable<IModelEntry<TModel>> object created by the specified element. You can also specify the mapping method for importing data into each IModelEntry<TModel> object.
Namespace: SnapObjects.Data
Assembly: SnapObjects.Data.dll
Syntax
public static IEnumerable<IModelEntry<TModel>> GetModelEntries<TModel>(
[NotNull]this IDataUnpacker packer,
[NotNull]string key,
[NotNull]MappingMethod mappingMethod) where TModel : class
Parameters
key System.String
The key specifying which element will be used to create the IEnumerable<IModelEntry<TModel>> object.
mappingMethod SnapObjects.Data.MappingMethod
A value of the MappingMethod enumerated datatype specifying the method for mapping columns.
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 and specifies the mapping method for importing data.
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 Example2(IDataUnpacker dataUnpacker)
{
// Gets the ModelEntries object according to the key value
var students = dataUnpacker.GetModelEntries<Person>(
"student", MappingMethod.Key);
// 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