开发者

Fetching with JoinQueryOver: Get greatgrandchildren, know father

开发者 https://www.devze.com 2023-04-01 07:00 出处:网络
Object Structure: A house has many rooms. A room has many tables. A table has many vases (on it). House > Rooms > Tables > Vases.

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();


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号