2011-01-28 2 views
0

내 위치의 검색 페이지를 완성하려고 시도했습니다. 이것은 내 그리드에서 페이징 설정을 시도한 첫 번째 시간입니다.SetMaxResults도 설정되어있을 때 NHibernate의 SetFirstResult (0) 메서드는 0 행을 반환합니다.

Fluent Nhibernate을 사용하고 있으며 SQL 2008 데이터베이스에서 데이터를 가져옵니다.

criteria.SetFirstResult(0).SetMaxResults(10);을 사용할 때 데이터를 다시받지 못할 것입니다. 데이터베이스를 프로파일 링하는 중이며 검색을 수행하는 SQL이 지금과 같이 보이지 않습니다. 문을 criteria.SetFirstResult(1).SetMaxResults(10);으로 변경하면 그리드에서 2-11 행을 볼 수 있으며 프로파일 러를 통해 생성 된 sql을 볼 수 있습니다. SetMaxResults이 임의의 값으로 설정되어있는 경우 왜 criteria.SetFirstResult(0)이 작동하지 않는지 알고 있습니까?

나는 아래의 유창한 NHibernate 코드 부착 오전 : 다시 가서이 문제를보고 한 후

public LocationSearchResults Search(string text, int pageNumber, int pageSize, string orderBy, string orderByDirection) 
    { 
     var criteria = Session.CreateCriteria(typeof(Location)); 
     var dis = Restrictions.Disjunction(); 
     dis.Add(Restrictions.Like("LocationName", text, MatchMode.Anywhere)); 
     dis.Add(Restrictions.Like("LocationAddress", text, MatchMode.Anywhere)); 
     dis.Add(Restrictions.Like("LocationCity", text, MatchMode.Anywhere)); 
     dis.Add(Restrictions.Like("LocationState", text, MatchMode.Anywhere)); 
     dis.Add(Restrictions.Like("LocationZip", text, MatchMode.Anywhere)); 
     criteria.Add(dis); 

     LocationSearchResults results = new LocationSearchResults(); 
     results.NumberOfResults = criteria.List<Location>().Count; 

     if (orderByDirection == "asc") 
     { 
      criteria.AddOrder(Order.Asc(orderBy)); 
     } 
     else 
     { 
      criteria.AddOrder(Order.Desc(orderBy)); 
     } 

     //criteria.SetFirstResult((pageNumber - 1) * pageSize).SetMaxResults(pageSize); 
     criteria.SetFirstResult(0); 
     criteria.SetMaxResults(10); 

     results.SearchResults = (List<Location>)criteria.List<Location>(); 

     return results; 
    } 
    #endregion 
+2

타겟팅 할 데이터베이스를 아는 것이 중요합니다. 유창하지 않습니다 여기 mattewr. –

+0

SQL 서버 2008 데이터베이스를 사용하고 있습니다. –

+0

아는 한, criteria.SetFirstResult (0)은 생략 한 것과 같은 효과가 있습니다. 쿼리를 두 번 실행하는 것 같습니다. 한 번 카운트를 얻고 다시 한 번 페이징을 기반으로 결과를 제한합니다. 당신은 페이징의 목적을 물리 치고 있습니다. – Vadim

답변

0

를, 무슨 일이 있었는지 알아 냈어. 나는 NHibernate가 실제로 오류를 던지고있는 것을 알아 차렸다. 메시지는 "쿼리는 'SELECT'또는 'DISTINCT SELECT'로 시작해야합니다. NHibernate 2nd lvl cache, custom query, sqldialect의 첫 번째 대답은 내 문제를 해결했습니다. 설정 파일에서 use_sql_comments를 false로 설정해야했습니다.