以下是我正在使用的代码。对我来说似乎很简单。但是我在最后一行,即 return 语句中得到了 NullReferenceException。这是堆栈跟踪:
FailedSystem.NullReferenceException:对象引用未设置为对象的实例。在 NHibernate.Criterion.Junction.ToSqlString(ICriteria 条件,ICriteriaQuery 条件查询,IDictionary
2 enabledFilters) at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetWhereCondition(IDictionary
2 enabledFilters)在 NHibernate.Loader.Criteria.CriteriaJoinWalker..ctor(IOuterJoinLoadable 持久性,CriteriaQueryTranslator 翻译器,ISessionFactoryImplementor 工厂,CriteriaImpl 条件,字符串 rootEntityName,IDictionary2 enabledFilters) at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, String rootEntityName, IDictionary
2 enabledFilters)在 NHibernate.Impl.SessionImpl.List(CriteriaImpl 标准,IList 结果) 在 NHibernate.Impl.CriteriaImpl.List(IList 结果) 在 NHibernate.Impl.CriteriaImpl.List()
public List<Person> Search(string keyword)
{
ICriteria criteria = session.CreateCriteria(typeof (Person));
Disjunction disjunction = Restrictions.Disjunction();
{
// In here, there is a whole lot of business logic adding around 20 conditions to the disjunction
}
criteria.Add(disjunction);
return criteria.List<Person>() as List<Person>;
}