These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: SQL Criteria Expressions and retrieving column aliases
PostPosted: Mon Jun 23, 2008 1:03 pm 
Newbie

Joined: Mon Jul 02, 2007 7:09 am
Posts: 4
Hibernate version: 2.0.0 Alpha 2

Name and version of the database you are using: SQL Server 2005

How do you retrieve the column alias for a computed (formula) property when using Expression.Sql?

For example, I have a property generated using:

Code:
    <property name="BiographyLocalised" type="System.String" not-null="true"
      formula="CASE WHEN :LanguageFilter.IsInitialised = 1 THEN IsNull((select WT.Name from Translation WT where WT.EntityID = ContactID and WT.TranslationTypeID = :LanguageFilter.ContactBiographyTranslationTypeID and WT.LanguageID = :LanguageFilter.LanguageID), Biography) ELSE Biography END"
    />


I want to run a Contains() expression on this property, for which I must use Expression.SQL. How can I get NHibernate to replace the column name with the generated SQL alias?

Code:
c.Add(Expression.Sql("contains({alias}.BiographyLocalised, ?)", query.ToSafeContainsQuery(), NHibernateUtil.String))


Does not work because BiographyLocalised is a formula column and does not exist in the table represented by {alias}.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.