IDataStore<TModel>.SetModel(int row, TModel model) Method
.NET Standard 2.x
Sets the data of a TModel
object to the specified row of the DataStore.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
void SetModel(int row, TModel model);
Parameters
row
System.Int32
The zero-based number of the row where data will be set. This row must exist.
model
TModel
The TModel
instance which will be set to the specified row in the primary buffer of DataStore.
Examples
The following code example demonstrates how to use the SetModel
method to add a new data record in the DataStore.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStore_GenericExamples
{
public class SetModelExample
{
private readonly SchoolContext _context;
public SetModelExample(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);
// Retrieves rows from the database for datastore.
datastore.Retrieve();
var department = datastore.GetModel(0);
Console.WriteLine("Before SetModel, Departmentid:{0}, Name:{1}, Budget:{2}," +
"Startdate:{3}, Administrator:{4}",
department.Departmentid, department.Name, department.Budget,
department.Startdate, department.Administrator);
// Modifies entity data.
department.Name = "New Department";
department.Budget = 280000;
department.Startdate = DateTime.Now;
department.Administrator = 1;
// Populates the first row with the D_Department object.
datastore.SetModel(0, department);
// Commits changes to database
datastore.Update();
department = datastore.GetModel(0);
Console.WriteLine("After SetModel, Departmentid:{0}, Name:{1}, Budget:{2}," +
"Startdate:{3}, Administrator:{4}",
department.Departmentid, department.Name, department.Budget,
department.Startdate, department.Administrator);
/*This code produces the following output:
Before SetModel, Departmentid:1, Name:Engineering, Budget:350000.00,
Startdate:2007-09-01 00:00:00, Administrator:2
After SetModel, Departmentid:1, Name:New Department, Budget:280000.00,
Startdate:2020-03-31 10:25:16, Administrator:1
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department