Richard,
why not a IQueryOver method or an extension method ?
var usersQuery =
mySession.QueryOver<User>()
...
.OrderBy(x => x.LastName).Asc
.Skip(page * pageSize)
.Take(pageSize);
var count = usersQuery.Count();
or
var count = usersQuery.RowCount();
2010/3/6 Richard Brown (gmail) <[email protected]>
> Hi Adam,
>
> There's now a QueryOverTransformer in the trunk code, so you can write:
>
> var usersQuery =
>
> mySession.QueryOver<User>()
> ...
> .OrderBy(x => x.LastName).Asc
> .Skip(page * pageSize)
> .Take(pageSize);
>
> var pagedUsers = usersQuery.List();
>
> var count =
> QueryOverTransformer.TransformToRowCount(usersQuery)
> .UniqueResult<int>();
>
> Sorry for the delay in implementing it.
>
>
> Richard
>
> --------------------------------------------------
> From: "Schotime" <[email protected]>
> Sent: Saturday, February 13, 2010 10:32 AM
>
> To: "nhusers" <[email protected]>
> Subject: [nhusers] Re: QueryOver issues
>
>
> That makes sense.
>> This would be a pretty common scenario i would think.
>>
>> Thanks for the reply.
>>
>> Adam
>>
>> On Feb 13, 9:11 pm, "Richard Brown \(gmail\)"
>> <[email protected]> wrote:
>>
>>> Hi Adam,
>>>
>>> The short answer is 'yes'. QueryOver behaves the same as ICriteria in
>>> this
>>> example ... adding conditions to the query changes the query itself.
>>>
>>> ICriteria has a corresponding CriteriaTransformer class which can be used
>>> to
>>> clone the criteria for exactly this sort of thing. I'll have a think and
>>> see if we need a QueryOverTransformer class to do something similar.
>>>
>>> IQueryOver does allow you access to the underlying ICriteria, so one
>>> option
>>> might be to do something like this:
>>>
>>> var users =
>>> mySession.QueryOver<User>()
>>> ...
>>> .OrderBy(x => x.LastName).Asc
>>> .Skip(page * pageSize)
>>> .Take(pageSize);
>>>
>>> var pagedUsers = users.List();
>>>
>>> var count =
>>> CriteriaTransformer.Clone(users.UnderlyingCriteria)
>>> .ClearOrders()
>>> .SetProjection(Projections.RowCount())
>>> .UniqueResult<int>();
>>>
>>> Hope that helps, and I'll see about getting a QueryOverTransformer (and
>>> probably IQueryOver.ClearOrders()) added to NH.
>>>
>>> Richard
>>>
>>> --------------------------------------------------
>>> From: "Schotime" <[email protected]>
>>> Sent: Friday, February 12, 2010 9:45 PM
>>> To: "nhusers" <[email protected]>
>>> Subject: [nhusers] QueryOver issues
>>>
>>>
>>>
>>> > Was trying out the new QueryOver since Linq doesn't have fetch yet,
>>> > but i received a different response than expected.
>>>
>>> > var users =
>>> > MvcApplication.SessionFactory.GetCurrentSession()
>>> > .QueryOver<User>().Fetch(x=>x.Roles).Eager;
>>>
>>> > if (!_userSession.IsUserInRole(UserRoles.Superuser))
>>> > users = users.Where(x => x.Company == user.Company);
>>>
>>> > int count =
>>> > users.Select(Projections.Count("id")).UniqueResult<int>();
>>>
>>> > var pagedUsers = users.OrderBy(x =>
>>> > x.LastName).Asc.Skip(page * pageSize).Take(pageSize).List();
>>>
>>> > to which i receive this error
>>>
>>> > Column "Users.LastName" is invalid in the ORDER BY clause because it
>>> > is not contained in either an aggregate function or the GROUP BY
>>> > clause.
>>>
>>> > Now in linq this runs too queries but it looks like QueryOver doesn't
>>> > return the instance, but modifies the existing one. Is this correct?
>>> > Do i need to repeat some logic to get the count as well?
>>>
>>> > Adam
>>>
>>> > --
>>> > 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]<nhusers%[email protected]>
>>> .
>>> > For more options, visit this group at
>>> >http://groups.google.com/group/nhusers?hl=en.
>>>
>>
>> --
>> 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]<nhusers%[email protected]>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/nhusers?hl=en.
>>
>>
>>
> --
> 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]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>
--
Fabio Maulo
--
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.