DataStoreDataExtensions.ExportJson(this IDataStoreBase dataStore, bool changedOnly, MappingMethod mappingMethod) Method
.NET Standard 2.x
Exports all rows or only the changed rows from DataStore to a DataWindow JSON string.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public static string ExportJson(this IDataStoreBase dataStore, bool changedOnly, MappingMethod mappingMethod);
Parameters
changedOnly
System.Boolean
A boolean
specifying the changing flag.
True
: to export the changed rows only (and all rows in the delete buffer).
False
(default): to export all rows.
mappingMethod
SnapObjects.Data.MappingMethod
A value of the MappingMethod
enumerated datatype specifying the method for mapping columns.
Returns
System.String
Returns the JSON string.
Examples
The following code example demonstrates how to export the department records to JSON strings using different changedOnly
arguments. When changedOnly
is true
, exports the modified data from primary/filter/delete buffers to a JSON string; When changedOnly
is false
, exports all data from primary/filter/delete buffers to a JSON string.
using SnapObjects.Data;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.DataStoreDataExtensionsExamples
{
public class ExportJsonExample
{
private readonly SchoolContext _context;
public ExportJsonExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example2()
{
// Instantiates the datastore with datawindow: d_department
var datastore = new DataStore("d_department", _context);
// Generates data in the primary/delete/filter buffers for this example.
datastore.Retrieve();
datastore.DeleteRow(0);
datastore.SetItem(0, 1, "department name");
datastore.SetFilter("departmentid < 5");
datastore.Filter();
// When changeOnly is true, exports the modified data from
// primary/filter/delete buffers
string json1 = datastore.ExportJson(true, MappingMethod.Index);
Console.WriteLine("datastore.ExportJson(true, " +
"MappingMethod.Index):");
Console.WriteLine(json1);
/*The exported JSON file is:
ExportJson2_1.json
*/
// When changeOnly is false, exports all data from
// primary/filter/delete buffers
string json2 = datastore.ExportJson(false, MappingMethod.Index);
Console.WriteLine("datastore.ExportJson(false, " +
"MappingMethod.Index):");
Console.WriteLine(json2);
/*The exported JSON file is:
ExportJson2_2.json
*/
}
}
}
Example Refer To
Model Class: D_Department
JSON Files: ExportJson2_1 ExportJson2_2
DataWindow File: d_department
Applies to
.NET Standard
2.x