Hmm... I just played around a bit with the new trunk version of NHibernate and the Future<T> methods... So far it's a solution to the problem I mentioned of not having typed multicriterias, but it does impose some rather odd design issues.
If I wan't to return the virtual row count as an out parameter of a method, I must make sure not to call .Value of FutureValue<T> before I have created my real query as this: 1. construct base query 2. assign the total row count criteria.FutureValue<int> to a temporary variable based on the base query (I'm using CriteriaTransformer.TransformToRowCount(criteria)) - Not calling .Value 3. complete query (add projections, filtering, ordering etc.) 4. assign criteria.Future<T> to temporary variable (executes both queries) 5. set out parameter of count using future count.Value 6. return resultset enumerable This is of course my own design oddities, which can be corrected in some ways, but in it's entirety it does look weird, and never the less, it a very cool feature! :D On 10 Mar., 21:36, ccollie <[email protected]> wrote: > if you're using trunk, try Future<T> and FutureValue<T> > > On Mar 10, 12:59 pm, TigerShark <[email protected]> wrote: > > > Oh, and BTW, I have looked at MultiCriteria, but it seems it can't > > return typed resultsets. But if you don't manipulate the resultset and > > uses it to bind directly, it might be worth taking a look at that, as > > it can perform your task in a single db call. > > > On 10 Mar., 17:57, TigerShark <[email protected]> wrote: > > > > I usually perform a count on my criteria before performing any paging. > > > That way I issue two selects, one for the resultset count and another > > > for the actual resultset. > > > > Normally I do something like this: > > > > public IEnumerable<ResultObject> GetPagedResultSet(out int count, > > > QueryRange range, params Order[] orders) { > > > var criteria = currentSession.CreateCriteria(typeof(ResultObject)) > > > .SetProjection(Projections.Count(Projections.Id())); > > > > count = criteria.UniqueResult<int>(); > > > > criteria.SetProjection(null); > > > > if(!QueryRange.IsNullOrEmpty(range)) { > > > range.Apply(criteria); > > > } > > > > if(orders != null) { > > > foreach(var order in orders) { > > > criteria.AddOrder(order); > > > } > > > } > > > > return criteria.List<ResultObject > > > > } > > > > The code above is from memory, and might be subject to your own > > > changes :) > > > > Furthermore the QueryRange class is one I have created to ease the > > > paging. I can post the code for it, if you'd like. > > > > On 10 Mar., 17:33, Robin Nadeau <[email protected]> wrote: > > > > > Is there a way to get the item count from the dataset when doing paging? > > > > > -- > > > > Robin Nadeau, B.Eng. > > > > Software Developer --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
