0

I have a Class A that have a class B List ... So, with QueryOver I have :

ClassB lb = null;  
var result = session.QueryOver<ClassA>
        .JoinAlias(x => x.ListB, () => lb, JoinType.LeftOuterJoin)
        .Where(() => lb.Property == 1)
        .List<ClassA>();

How Can I do that using Nhibernate Query<> ?

Thanks

Paul

Paul
  • 12,359
  • 20
  • 64
  • 101

1 Answers1

1

Assuming what you want to do is get a list of ClassA having at least one ClassB with Property == 1:

var result = session.Query<ClassA>()
                    .Where(a => a.ListB.Any(b => b.Property == 1))
                    .ToList();

This wouldn't be an outer join, though. You might emulate that by adding || !a.ListB.Any().

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154
  • The generated SQL is weird and I got an cast error on c# (But the sql worked on SQL Manager) ... If its the only way, I think QueryOver is the best option, right? – Paul Jun 05 '12 at 12:27
  • I don't have your source, so I can't know what your cast error is. About the sql being weird... uh? It's not like you have to maintain it manually. Last, QueryOver can be better or not, I still don't have enough information about what you need. – Diego Mijelshon Jun 05 '12 at 12:32
  • My example here is very simple... But I can have a complex scenario like that : Object A -> List B -> Object C -> List D -> Object E -> Property E ... So I have to create a query to return Class A based in Property E ... – Paul Jun 05 '12 at 13:17
  • @Paul, I don't see any reference to C or D in your original query. – Diego Mijelshon Jun 05 '12 at 13:33