IDataStoreBase.GetDataExporter(DataFormat dataFormat) Method
.NET Standard 2.x
Gets the DataStore exporter, you need to specify the data export format (DataFormat
).
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
IDwDataExporter GetDataExporter(DataFormat dataFormat);
Parameters
dataFormat
SnapObjects.Data.DataFormat
Format of the exported data.
Returns
DWNet.Data.IDwDataExporter
DataStore data exporter.
Examples
The following code example demonstrates how to get DataStore exporter in the specified format.
using DWNet.Data;
using SnapObjects.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreBaseExamples
{
public class GetDataExporterExample
{
private readonly SchoolContext _context;
public GetDataExporterExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example()
{
// Instantiates a DataStore object with datawindow: d_department.
var datastore = new DataStore("d_department", _context);
datastore.Retrieve();
// Only one data in DataStore after data is filtered
// by Departmentid=1, Engineering=Engineering
datastore.Filter("departmentid = 1");
// Gets DataStore exporter in JSON format
var exporter = datastore.GetDataExporter(DataFormat.Json);
string export_json = exporter.Export();
Console.WriteLine("Export Json:{0}", export_json);
// Equivalent to exporter.Export(false)
string exportPlain_json = exporter.ExportPlain();
Console.WriteLine("ExportPlain Json:{0}", exportPlain_json);
// Gets the first row in the filter buffer
string exportRow_json = exporter.ExportRow(0, DwBuffer.Filter);
Console.WriteLine("ExportRow Json:{0}", exportRow_json);
// Gets DataStore exporter in XML format
exporter = datastore.GetDataExporter(DataFormat.Xml);
string xml = exporter.Export(false);
Console.WriteLine("Export Xml:{0}", xml);
/*This code produces the following output:
Export Json: {"identity":"70c86603-983b-4bd9-adbc-259436e43cbd","version":1.0,"platform":"C#","mapping-method":0,"dataobject":{"name":"d_department","meta-columns":[{"name":"Departmentid","index":0,"datatype":"System.Int32","nullable":0},{"name":"Name","index":1,"datatype":"System.String","nullable":0},{"name":"Budget","index":2,"datatype":"System.Decimal","nullable":0},{"name":"Startdate","index":3,"datatype":"System.DateTime","nullable":0},{"name":"Administrator","index":4,"datatype":"System.Int32","nullable":1}],"primary-rows":[{"row-status":-1,"columns":{"Departmentid":[1],"Name":["Engineering"],"Budget":[350000.0000],"Startdate":["2007-09-01T00:00:00"],"Administrator":[2]}}]}}
ExportPlain Json: [{"Departmentid":1,"Name":"Engineering","Budget":350000.0000,"Startdate":"2007-09-01T00:00:00","Administrator":2}]
ExportRow Json: {"Departmentid":2,"Name":"English","Budget":120000.0000,"Startdate":"2007-09-01T00:00:00","Administrator":6}
Xml:
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfD_Department>
<D_Department>
<Departmentid>1</Departmentid>
<Name>Engineering</Name>
<Budget>350000.0000</Budget>
<Startdate>2007-09-01T00:00:00</Startdate>
<Administrator>2</Administrator>
</D_Department>
</ArrayOfD_Department>
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x