2

I can't build the lambda expressions in NHibernate JoinQueryOver that solve the SQL command below:

SELECT 
    A.STATUS,
    B.NUMBER,
    B.OTHER_NUMBER,
    A.Date01,
    A.Date02
FROM 
    B, 
    C, 
    A
WHERE
        A.ID = C.ID
    AND     B.ID = C.ID

All tables in SQL command above are in Entities with same name (A, B, C) and the inner join is in WHERE clause.

How can I build the NHibernate lambda query?

Thanks,

Roosevelt

roosevelt
  • 21
  • 1
  • 2

1 Answers1

4
A a = null;
B b = null;
var result = session.QueryOver<C>()
    .JoinAlias(c => c.A, () => a)
    .JoinAlias(c => c.B, () => b)
    .Select(c => a.Status, c => b.Number, c => b.Other_Number, c => a.Date01, c => a.Date02 )
    .List<object[]>();
Firo
  • 30,626
  • 4
  • 55
  • 94
  • This will not work in case when we need to set up conditions for A or B entities. Nhibernate will not find these aliases for the query – Anubis Apr 16 '12 at 08:51
  • @Anubis sorry i don't understand. `.Where(() => a.Prop == Something)` works for me – Firo Apr 16 '12 at 13:32
  • Fwiw, the OP did ask for `.JoinQueryOver` rather than `JoinAlias`. – ruffin Jul 15 '13 at 12:41
  • 1
    @ruffin JoinAlias and JoinQueryOver are the same for all intents and purposes http://stackoverflow.com/questions/5416560/what-is-the-difference-between-joinqueryover-and-joinalias – Shagglez Aug 06 '13 at 10:32