0
votes

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

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

    var query = 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.

1

1 Answers

1
votes

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.