views:

494

answers:

1

Hi

I have this query:

criteria = session.CreateCriteria(typeof (Building))
    .CreateAlias("Estate", "estate")
    .SetProjection(Projections.ProjectionList()
                       .Add(Property.ForName("Name"), "BuildingName")
                       .Add(Property.ForName("estate.Name"), "EstateName")
                       .Add(Projections.SqlProjection(
                                "(estate1_.BBRMunicipalityNumber + '-' + estate1_.BBREstateNumber + '-' + {alias}.BBRBuildingNumber)" + " as BBRNumber",
                                new[] { "BBRNumber" },
                                new[] { NHibernateUtil.String }),
                            "BBRNumber"))

Is there a way that I can get the SQL alias for "estate" like writing {estate} in the SQL string? {estate} does not work. Now I ended up hardcoding the alias in the SQL string, but that doesn't seem very solid.

If I understand the docs correctly this should be possible. I'm using NH2.0.1.

/Asger

+1  A: 

Hi Asger,

Not a direct answer to your question, but: Why don't you query the three values separately and do the concatenation in your code instead of using the database for that?

To answer your question: In Hibernate v3 (java, sorry) there is a getColumnAlias method on the Projection interface. I'm not able to find its counterpart in NHibernate.

Cheers

Maarten Winkels
Hi Maarten, thank you very much for your reply. The getColumnAlias is exactly what I'm looking for... but as you say, it doesn't seem to exist in NH. But as for your suggestion, you are very right, I grabbed the query part from some other part of my code, where I'm going to use a HAVING clause on the projected value, so there it makes sense - but in this case it doesn't. Thanks for pointing that out!
asgerhallas