If I were to select some rows based on certain criteria, I could use an object ICriterionin NHibernate.Criterion, for example:
public List<T> GetByCriteria()
{
SimpleExpression newJobCriterion =
NHibernate.Criterion.Expression.Eq("LkpStatu", statusObject);
ICriteria criteria = Session.GetISession().CreateCriteria(typeof(T)).SetMaxResults(maxResults);
criteria.Add(newJobCriterion );
return criteria.List<T>();
}
Or I can use the LINQ where clause to filter what I want:
public List<T> GetByCriteria_LINQ()
{
ICriteria criteria = Session.GetISession().CreateCriteria(typeof(T)).SetMaxResults(maxResults);
return criteria.Where(item=>item.LkpStatu=statusObject).ToList();
}
I would prefer the second, of course. Because
- It gives me a strong typing
- I don't need to learn another syntax like NHibernate
The problem is, is there a performance advantage in the first for the second? From what I know, the first one will create SQL queries, so it will filter the data before going into memory. How effective is such performance to justify its use?
source
share