To make our Data Access Object more functional, we will need to create our GetAll()
method that simply returns all records. We will also want to create GetAll()
and GetCountOfAll()
methods with some additional parameters that will let us take advantage of the paging functionality of the ASP.NET framework controls when we have larger result sets.
Using an ICriteria
object, it's really simple to write a GetAll()
method. All we have to do is new up an ICriteria
object, and call .List<T>()
on it. It will retrieve all of the objects of that type. The code for our GetAll()
method would look like this:
public IList<Contact> GetAll() { ICriteria criteria = Session.CreateCriteria<Contact>(); return criteria.List<Contact>(); }
It is just as simple in VB.NET:
Public Function GetAll() As IList(Of Contact) Dim criteria As ICriteria = Session.CreateCriteria(Of Contact)() Return criteria.List(Of Contact)() End Function