IDataStore.DeleteRow<TModel>(Predicate<TModel> predicate) Method
.NET Standard 2.x
Deletes the row(s) which meet the condition from the primary buffer of the DataStore. The deleted row(s) will be moved to the delete buffer of the DataStore.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public bool DeleteRow<TModel>(Predicate<TModel> predicate);
Type Parameters
TModel
The type of a model
class that matches with the current DataObject
.
Parameters
predicate
System.Predicate<TModel>
A function to evaluate each row in the primary buffer for a condition.
Returns
System.Boolean
Returns true
if successfully deleting the row(s); returns false
if no row in the primary buffer is found satisfying the condition.
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>(Predicate<TModel>
) method to move those rows which meet the condition 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 Example3()
{
// 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);
// Deletes the records (Budget > 200000.00).
// There are 2 such records.
datastore.DeleteRow<D_Department>(a => a.Budget > 200000.00m);
// This datastore has 2 records in the primary buffer
Console.WriteLine("Primary buffer Rowcount: {0}",
datastore.RowCount);
// This datastore has 2 records in the delete buffer
Console.WriteLine("Delete buffer Rowcount: {0}",
datastore.DeletedCount);
/*This code produces the following output:
Retrieved Rowcount: 4
Primary buffer Rowcount: 2
Delete buffer Rowcount: 2
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x