Knight Data Access Layer
Search Count
Basic Tasks C# > Loading Data > Search Count

The SearchCount method is useful when needing to know how many total records there are for a search.  This is important when paging is performed.

 

//Create a new Person to save to the database

Person currentPerson = new Person();

currentPerson.FirstName = "John";

currentPerson.LastName = "Smith";

 

//Get the current instance of the helper

IDataHelper db = DataHelper.SessionFactory();

 

//Save it to the database

db.Save(currentPerson);

 

//Search parameters

Person searchParm = new Person();

searchParm.FirstName = "John";

 

//Search for records based on the passed in search object

long count= _db.SearchCount(searchParm);