IDataStore.Contains(TModel item) Method
.NET Standard 2.x
Determines whether a data row exists in the primary buffer of the DataStore.
Namespace: DWNet.Data
Assembly: DWNet.Data.dll
Syntax
public bool Contains(TModel item);
Parameters
item
TModel
A TModel
object which represents a row of data.
Returns
System.Boolean
Returns true
if the data row is found in the primary buffer of the DataStore; otherwise, false
.
Remarks
A model object which represents a data row is a reference type. The Contains
method tests for reference equality (Reference equality means that the object variables that are compared refer to the same object).
It returns true
once the item
argument and the data row in the primary buffer refer to the same model object. See examples for elaboration.
Examples
The following code example demonstrates how to use the Contains
method.
using Appeon.ApiDoc.Models;
using DWNet.Data;
using System;
namespace Appeon.ApiDoc.IDataStoreExamples
{
public class ContainsExample
{
private readonly SchoolContext _context;
public ContainsExample(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);
datastore.Retrieve();
// Creates a D_Department object and populates it with data
var department = new D_Department
{
Departmentid = 10,
Name = "department name",
Budget = 10m,
Startdate = DateTime.Now,
Administrator = 2
};
// The Contains method returns false
Console.WriteLine("DataStore contains item: {0}",
datastore.Contains(department));
// Appends the department data to datastore
datastore.Add(department);
// The Contains method returns true
Console.WriteLine("DataStore contains item: {0}",
datastore.Contains(department));
// Changes a data value
department.Administrator = 3;
// The Contains method still returns true
// because it compares the reference address, not values.
Console.WriteLine("Datastore contains item {0}",
datastore.Contains(department));
/*This code produces the following output:
DataStore contains item: False
DataStore contains item: True
DataStore contains item: True
*/
}
}
}
Example Refer To
Model Class: D_Department
DataWindow File: d_department
Applies to
.NET Standard
2.x