IDataStore.AddRow<TModel>(IEnumable<TModel> list) Method
.NET Standard 2.x
Generic method. Appends a sequence of TModel
objects as row(s) to the end of the primary buffer in the DataStore and returns the index of the first row added. TModel
must match with the DataObject
property of the DataStore.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public int AddRow<TModel>(IEnumerable<TModel> list);
Type Parameters
TModel
The type of a model
class that matches with the current DataObject
.
Parameters
list
System.Collections.Generic.IEnumerable<TModel>
A sequence of TModel
objects which match with the DataObject
property of the DataStore.
Returns
System.Int32
Returns the zero-based index number of the first row added.
Remarks
The status flag for a newly added row is ModelState.NewModified
, and the row is included in the modified count.
Examples
The following code example demonstrates how to use the AddRow
method to add multiple rows of data to the DataStore.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
using System.Collections.Generic;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class AddRowExample
{
private readonly SchoolContext _context;
public AddRowExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example3()
{
// Instantiates a DataStore object with dataobject: d_department.
var datastore = new DataStore("d_department", _context);
Console.WriteLine("Before AddRow, Rowcount: {0}", datastore.Retrieve());
// Creates a list of D_Department objects.
var departmentList = new List<D_Department>();
var department = new D_Department
{
Departmentid = 10,
Name = "department name",
Budget = 10,
Startdate = DateTime.Now,
Administrator = 1
};
departmentList.Add(department);
var department2 = new D_Department
{
Departmentid = 20,
Name = "department name2",
Budget = 20,
Startdate = DateTime.Now,
Administrator = 2
};
departmentList.Add(department2);
// Adds the model list to datastore.
// AddRow returns the zero-based index number of the first row added.
int currentRow = datastore.AddRow<D_Department>(departmentList);
Console.WriteLine("Addrow return value: {0}", currentRow);
// Commits changes to database.
datastore.Update();
Console.WriteLine("After Update and Retrieve, Rowcount: {0}",
datastore.Retrieve());
/*This code produces the following output:
Before AddRow, Rowcount: 4
Addrow return value: 4
After Update and Retrieve, Rowcount: 6
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x