IDataStore.CopyTo<TModel>(TModel[] array, int arrayIndex) Method
.NET Standard 2.x
Copies all rows from the primary buffer of the DataStore to a compatible one-dimensional array, starting at the specified array index.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public void CopyTo<TModel>(TModel[] array, int arrayIndex);
Parameters
array
TModel
The one-dimensional array which is the destination for the rows copied from the primary buffer of the DataStore.
arrayIndex
System.Int32
The zero-based index in array at which copying begins.
Examples
The following code example demonstrates how to use the CopyTo
method.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class CopyToExample
{
private readonly SchoolContext _context;
public CopyToExample(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);
// This datastore has 4 records
datastore.Retrieve();
var departments = new D_Department[5];
// Creates a D_Department object and populates it with data.
var department = new D_Department
{
Departmentid = 20,
Name = "New Department",
Budget = 20,
Startdate = DateTime.Now,
Administrator = 2
};
// Sets the first element of the departments array.
departments[0] = department;
// Copies 4 records to the departments array.
// It starts at the index 1 of the array, so the first element (index = 0)
// in the departments array will not be affected.
datastore.CopyTo(departments, 1);
foreach( var d in departments)
{
Console.WriteLine("Department Name: {0}", d.Name);
}
/*This code produces the following output:
Department Name: New Department
Department Name: Engineering
Department Name: English
Department Name: Economics
Department Name: Mathematics
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x