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>();
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:
Movie film = null;
GenreSummary summary = null;
var summaryList =
s.QueryOver<MovieGenre>()
.JoinAlias(mg => mg.Film, () => film)
.SelectList(l => l
.SelectGroup(() => film.Title).WithAlias(() => summary.Title)
.SelectGroup(() => film.Premier).WithAlias(() =>
summary.Premier)
.SelectCount(mg => mg.Id).WithAlias(() => summary.GenreCount))
.TransformUsing(Transformers.AliasToBean<GenreSummary>())
.List<GenreSummary>();
Let me know if that helps.
Cheers,
Richard
-----Original Message-----
From: Macko
Sent: Monday, December 27, 2010 9:22 AM
To: nhusers
Subject: [nhusers] Summary entities and QueryOver
Hello,
I'm exploring NH3 which is great but I'm stuck at creating simple
summaries.
I'm creating sample movie database.
I want to display every Movie entity with count of genres that is
associated with movie.
The output list should look like this:
MovieId | Title | Premiere | Genres Count
-----------------------------------------------------------------
3 | bla bla | 1990-01-01 | 2
Using SQL it would look like this:
select f.*, isnull(fg.counter, 0) as genres_count
from dbo.movie f left join
(
select id_movie, count(id_genre) as counter
from dbo.movie_genres
group by id_movie
) fg on f.id = fg.id_movie
Now aggregation that counts genres for every movie using QueryOver:
GenreSummary alias = null;
var genresQuery = QueryOver.Of<MovieGenre>()
.SelectList(lista => lista
.SelectGroup(o => o.Film.Id).WithAlias(() => alias.MovieId)
.SelectCount(o => o.Genre).WithAlias(() => alias.GenresCount))
.TransformUsing(Transformers.AliasToBean<GenreSummary>());
Movie Query:
var movieQuery = QueryOver.Of<Movie>().ToList();
So now how to join genresQuery with movieQuery to create summary
entity list let's say MovieSummary? Can it be done with 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.
--
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.