DataStorePackerExtensions.AddDataStore<TModel>([NotNull]this IDataPacker dataPacker,[NotNull]string key,[NotNull]IDataStore<TModel> value,[NotNull]bool format,[NotNull]bool changedOnly) Method
.NET Standard 2.x
Adds an IDataStore object as an element to the IDataPacker object, and specifies whether to export only the changed data from the IDataStore object.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public static void AddDataStore<TModel>(
[NotNull]this IDataPacker dataPacker,
[NotNull]string key,
[NotNull]IDataStore<TModel> value,
[NotNull]bool format,
[NotNull]bool changedOnly)
Parameters
dataPacker SnapObjects.Data.IDataPacker
The IDataPacker object that can package multiple types of data element together.
key System.String
The key for the element, which is the identifier of the element in the IDataPacker object.
value DWNet.Data.IDataStore
An IDataStore object, which is the value of the element to be added to the IDataPacker object.
format System.Boolean
DataWindow column headings format.
changedOnly System.Boolean
System.Boolean
True -- to export the changed rows in the IDataStore object only (and all rows of the delete buffer).
False -- to export all rows in the IDataStore object.
Examples
The following code example adds a DataStore object which contains only the changed data to the IDataPacker object.
using SnapObjects.Data;
using DWNet.Data;
using System;
using Appeon.ApiDoc.Models;
namespace Appeon.ApiDoc.DataStorePackerExtensionsExamples
{
public class AddDataStoreExample
{
private readonly SchoolContext _context;
public AddDataStoreExample(SchoolContext dataContext)
{
// Sets the data context.
_context = dataContext;
}
public void Example4()
{
// Instantiates a DataStore object with datawindow: d_department.
var dataStore = new DataStore<D_Department>(_context);
dataStore.Retrieve();
// Modifies the Name value of the first row to "Designer"
dataStore.SetItem(0, "Name", "Designer");
var dataPacker = new DataPacker();
// Adds datastore object to the current IDataPacker and exports only the changed data.
// Do not use DataWindow format.
var key = nameof(dataStore);
dataPacker.AddDataStore(key, dataStore, false, true);
// Gets all of the data in IDataPacker and shows the data in JSON format.
string text = dataPacker.GetTextString(DataFormat.Json);
Console.WriteLine(text);
/* This code example produces the following output:
{"dataStore":[{"Departmentid":1,"Name":"Designer","Budget":220000.0000,
"Startdate":"2007-09-01T00:00:00","Administrator":2}]}
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x