开发者

Problem with Skip and Take in NHibernate 3 Linq query

开发者 https://www.devze.com 2023-02-01 21:51 出处:网络
Using linq to NHibernate (NHibernate v3) I have the following LINQ query: var session = this.GetSession();

Using linq to NHibernate (NHibernate v3) I have the following LINQ query:

    var session = this.GetSession();
    var rgn = this.Get(regionId);

    var q开发者_运维百科uery = from t in session.Query<Tag>()
                where
                    !(
                        from trn in session.Query<Translation>() 
                        where trn.Region.Id == regionId 
                        select trn.Tag.Id
                     )
                     .Contains(t.Id)

                select new Translation() {Id = t.Id, Tag = t, Region = rgn, TagTranslation=""};

    var count = query.Count();
    var untranslatedTags = query.Skip((page - 1)*pageSize).Take(pageSize);
    var countAfterSkipAndTake = untranslatedTags.Count();
    return untranslatedTags.ToList();
} 

the count variable does indeed return the expected value. However countAfterSkipAndTake returns the same value. I would hve expected it to return pageSize (which in this case is 15). The final line untranslatedTags.ToList() returns an exception. I believe LINQ to NHibernate is not fully implemented, before I try and download the trunk can anyone see anything obvious I've done wrong.


I would guess, as I've had a similar problem in the past, is that the var count = query.Count(); is forcing nHibernate to compile the query, and therefore any future amends to it are futile as it's already been executed.

To test this out, remove that line and see if the countAfterSkipAndTake is now 15.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号