IDataStore.Add<TModel>(TModel item) Method
.NET Standard 2.x
Appends a TModel
object as a row to the end of the primary buffer in the DataStore. The TModel
class must be the model class matching with the DataStore's DataObject property.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public void Add<TModel>(TModel item);
Parameters
item
TModel
A TModel
object matching with the DataObject property of the current DataStore.
Remarks
A newly inserted row (with a row status flag of ModelState.New) is not included in the modified count until that row is populated with data (its row status flag becomes ModelState.NewModified).
Examples
The following code example demonstrates how to use the Add
method to append a row to the end of the DataStore.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class AddExample
{
private readonly SchoolContext _context;
public AddExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example()
{
// Instantiates a DataStore object with datawindow object: d_department.
var datastore = new DataStore("d_department", _context);
int rowCount = datastore.Retrieve();
Console.WriteLine("Before row is added, Rowcount: {0}", rowCount);
// Creates a D_Department object.
var department = new D_Department
{
Departmentid = 10,
Name = "department name",
Budget = 20,
Startdate = DateTime.Now,
Administrator = 2
};
// Appends the department data to the end of DataStore
datastore.Add(department);
// Commits changes to database
datastore.Update();
Console.WriteLine("After row is added, Rowcount: {0}",
datastore.Retrieve());
/*This code produces the following output:
Before row is added, Rowcount: 4
After row is added, Rowcount: 5
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x