Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fetching with JoinQueryOver: Get greatgrandchildren, know father

Object Structure: A house has many rooms. A room has many tables. A table has many vases (on it).

House > Rooms > Tables > Vases.

I'd like to use JoinQueryOver to select all tables with vases that are red - in a particular house.

I thought to do this:

var v = session.QueryOver<House>()
    .Where(x => x.ID == HouseID)
        .JoinQueryOver<Room>(x => x.Rooms)
            .JoinQueryOver<Table>(x => x.Tables)
                .JoinQueryOver<Vase>(x => x.Vases)
                    .Where(x => x.Color == "Red")
    .SingleOrDefault<House>();

This was an approach I tried (of the many that failed). I don't really want the House and Room info.

Ultimately, I'm looking for a List of Tables (in a particular house), with their collections of Vases (that are red) fetched.

Thanks for the help!

Edit

Something like this would be nice:

var v = session.QueryOver<Table>()
        .Where(x => x.Room.House.ID == HouseID) // this Where won't work.
            .JoinQueryOver<Vase>(x => x.Vases)
                .Where(x => x.Color == "Red")
        .List().ToList();
like image 392
cyrotello Avatar asked Feb 23 '23 03:02

cyrotello


1 Answers

var v = session.QueryOver<Table>()
    .JoinAlias(x => x.Room, () => room)
    .Where(() => room.House.ID == HouseID)
    .JoinQueryOver<Vase>(x => x.Vases)
        .Where(x => x.Color == "Red")
    .List();
like image 130
Firo Avatar answered Apr 07 '23 14:04

Firo