On 27 Gru, 20:29, "Richard Brown \(gmail\)" <[email protected]>
wrote:
> Hi Macko,
>
> What you have looks almost right to me.  I think you can pull the whole
> movie object in (which I think is what you were trying to do):
>
> GenreSummary summary = null;
> var summaryList =
>     s.QueryOver<MovieGenre>()
>         .SelectList(l => l
>             .SelectGroup(mg => mg.Film).WithAlias(() => summary.Film)
>             .SelectCount(mg => mg.Id).WithAlias(() => summary.GenreCount))
>             .TransformUsing(Transformers.AliasToBean<GenreSummary>())
>             .List<GenreSummary>();

Yes, you're right, but the problem is that if i want to include in
summary additional column (for example MovieTitle, PremiereDate) I
should include this columns using .SelectGroup (not .Select). This
QueryOver doesn't produce SQL which I gave in my post, but for small
amounts of data execution time is negligible low.

>
> Alternatively you could alias the reference to the movie too so that you can
> pull out the film's title (rather than it's ID, or the whole object) in this
> case:

I found a lot simplier solution to achive same result but it can gain
performance issues on large amount of data.

summaryList = session.Query<Movie>()
.Select( o => new MovieSummary()
{
 Id = o.Id,
 Title = o.Title,
 GenresCount = o.Genres.Count
}).ToList();

This Linq-2-NH query produces correlated subquery for every movie
record.

Thanks Richard

BTW. Can we force NH to produce more optimal SQLs using QueryOver?

--
Regards,
 Macko

-- 
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.

Reply via email to