tags:

views:

53

answers:

2

I have the following code:

Session.CreateCriteria<Foo>("foo")
    .CreateAlias("foo.Bar", "bar")
    .SetProjections(Projections.SqlProjection("bar.FirstName + ' ' + bar.LastName));

The problem is with the alias for the bar table in the SqlProjection.

The Hibernate docs say that "the string {alias} will be replaced by the alias of the root entity", but doesn't give any hint how you could access the aliases for non-root entities.

Is this possible?

A: 

Try this:

 Session.CreateCriteria<Foo>()
   .CreateCriteria("Bar")
      .SetProjections(Projections.SqlProjection("FirstName + ' ' + LastName)");
Torkel
A: 

Is there an Answer when the fields are not unique?

I am trying to get a method which will allow me to convert from "Bar" to "Bar1_" (or whatever NHIbernate will generate in future versions etc).

Have tried GetCriteriaByAlias("Bar") but the object does not have the querytime alias - only the in code one.

Any Advice? :-(

Rory