DataStoreUnpackerExtensions.GetDataStore([NotNull]this IDataUnpacker dataUnPackage,[NotNull]string key,[NotNull]DataContext context,[NotNull]MappingMethod importMapping) Method
.NET Standard 2.x
Gets an IDataStore
object created by the specified element, the DataWindow object specified by the element, and the DataContext
object. You can also specify the mapping method for importing data into the IDataStore
object.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public static IDataStore GetDataStore(
[NotNull]this IDataUnpacker dataUnPackage,
[NotNull]string key,
[NotNull]DataContext context,
[NotNull]MappingMethod importMapping)
Parameters
dataUnPackage
SnapObjects.Data.IDataUnpacker
The IDataUnpacker
object that can unpack a data package which contains multiple types of elements.
key
System.String
The key specifying which element will be used to get the IDataStore
object.
context
SnapObjects.Data.DataContext
A DataContext
object which will be used to get the IDataStore
object.
mappingMethod
SnapObjects.Data.MappingMethod
A value of the MappingMethod
enumerated datatype specifying the method for mapping columns.
Returns
Returns the newly created IDataStore
object.
Examples
The following code example demonstrates how to get an IDataStore
object from IDataUnpacker
according to a key name, specify the DataContext
, and specify the mapping method for importing data to DataStore.
using SnapObjects.Data;
using DWNet.Data;
using System;
using Appeon.ApiDoc.Models;
namespace Appeon.ApiDoc.DataStoreUnpackerExtensionsExamples
{
public class GetDataStoreExample
{
private readonly SchoolContext _context;
public GetDataStoreExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example6()
{
// 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 the DataStore object according to the key value and
// specifies DataContext name to _context and
// specifies the mapping method to Json Key.
var ds = dataUnpacker.GetDataStore(key, _context, MappingMethod.Key);
// Shows the departments.
for (int i = 0; i < ds.RowCount; i++)
{
Console.WriteLine("Row Status: {0}; Departmentid: {1}; Name: {2}",
ds.GetRowStatus(i),
ds.GetItem(i, "Departmentid"),
ds.GetItem(i, "Name"));
}
/* This code example produces the following output:
Row Status: NotTracked; Departmentid: 1; Name: Engineering
Row Status: NotTracked; Departmentid: 2; Name: English
Row Status: NotTracked; Departmentid: 4; Name: Economics
Row Status: NotTracked; Departmentid: 7; Name: Mathematics
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x