IDataStore.DeleteRow<TModel>(TModel model) Method
.NET Standard 2.x
Deletes the specified row (by the model object) from the primary buffer of the DataStore. The deleted row will be moved to the delete buffer of the DataStore.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public bool DeleteRow<TModel>(TModel model);
Type Parameters
TModel
The type of a model
class that matches with the current DataObject
.
Parameters
model
TModel
A TModel
object that represents the row of data to delete from the DataStore.
Returns
System.Boolean
Returns true
if successfully deleting the row(s); returns false
if no row in the primary buffer is found matching with the model
argument.
Remarks
The DeleteRow
method deletes a row from the DataStore primary buffer. If DataStore is not updatable, the storage related with the deleted row will be directly erased. If DataStore is updatable, DeleteRow
moves the row to the delete buffer. DataStore uses the value in the delete buffer to create the SQL DELETE statement. The row will not be deleted from the database table until Update
method is called; and the storage related with the deleted row will not be erased until the database is updated with the changes made to the DataStore and the update flag is reset by the Update
method.
Examples
The following code example demonstrates how to use the DeleteRow<TModel>(TModel)
method to move a model from the primary buffer to the delete buffer.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class DeleteRowExample
{
private readonly SchoolContext _context;
public DeleteRowExample(SchoolContext dataContext)
{
// Sets the data context
_context = dataContext;
}
public void Example2()
{
// Instantiates a DataStore object with datawindow: d_department.
var datastore = new DataStore("d_department", _context);
datastore.Retrieve();
// This datastore has 4 records
Console.WriteLine("Retrieved Rowcount: {0}",
datastore.RowCount);
// Gets the model object of the first row.
var department = datastore[0];
// Deletes the model object which
// represents the first row of datastore
datastore.DeleteRow(department);
// This datastore has 3 records in the primary buffer
Console.WriteLine("Primary buffer Rowcount: {0}",
datastore.RowCount);
// This datastore has 1 record in the delete buffer
Console.WriteLine("Delete buffer Rowcount: {0}",
datastore.DeletedCount);
/*This code produces the following output:
Retrieved Rowcount: 4
Primary buffer Rowcount: 3
Delete buffer Rowcount: 1
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x