DataStoreUnpackerExtensions.GetModelEntries<TModel>([NotNull]this IDataUnpacker packer,[NotNull]string key,[NotNull]MappingMethod importMapping) Method
.NET Standard 2.x
Gets an IEnumerable
object as an element to the IDataUnpacker
object. You can also specify the mapping method for export data from the IDataStore
object.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public static IEnumerable<IModelEntry<TModel>> GetModelEntries<TModel>(
[NotNull]this IDataUnpacker packer,
[NotNull]string key,
[NotNull]MappingMethod importMapping) where TModel : class
Parameters
packer
SnapObjects.Data.IDataUnpacker
The IDataUnpacker
object that can unpack a data package which contains multiple types of elements.
key
System.String
The key for the element, which is the identifier of the element in the IDataUnpacker
object.
mappingMethod
SnapObjects.Data.MappingMethod
A value of the MappingMethod
enumerated datatype specifying the method for mapping columns.
Returns
IEnumerable<IModelEntry<TModel>>
Returns the newly created IEnumerable<IModelEntry<TModel>>
object.
Examples
The following code example demonstrates how to get an IEnumerable<IModelEntry<TModel>>
object from IDataUnpacker
according to a key and specify the mapping method.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using SnapObjects.Data;
using System;
using System.Linq;
namespace Appeon.ApiDoc.DataStoreUnpackerExtensionsExamples
{
public class GetModelEntriesExample
{
private readonly SchoolContext _context;
public GetModelEntriesExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example2()
{
// Instantiates a DataStore object with datawindow: d_department.
var dataStore = new DataStore("d_department", _context);
dataStore.Retrieve();
var dataPacker = new DataPacker();
// Adds the DataStore object as an element to the current IDataPacker
// and adds the DataStore name as the key name for the element
// and uses the DataWindow format.
var key = nameof(dataStore);
dataPacker.AddDataStore(key, dataStore, true);
// Gets a string in the specified format which represents all elements
// in the current `IDataPacker` object.
string text = dataPacker.GetTextString(DataFormat.Json);
var dataUnpacker = new DataUnpacker(text, DataFormat.Json);
// Gets an `IEnumerable<IModelEntry<TModel>>` object from dataUnPacker
// according to a key and specify the mapping method.
var entries = dataUnpacker.GetModelEntries<D_Department>(key, MappingMethod.Key);
Console.WriteLine("GetModelEntries Count: {0}", entries.Count());
/* This code example produces the following output:
GetModelEntries Count: 4
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x