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: Howto get the NH generated SQL table alias like with {alias}
PostPosted: Tue Oct 28, 2008 6:48 am 
Newbie

Joined: Tue Oct 28, 2008 6:09 am
Posts: 1
Hi

Is there a way to get the NHibernate table SQL alias name inside an SQL in criteria?
Somthing like this:

TableA
ID integer primary key
OznakaA varchar(2)
NazivA varchar(30)

TableB
ID integer primary key
TableAID integer foreign key
NazivB varchar(30)

the classes would look like
Code:
public class TableA
{
   public virtual int ID {get;set;}
   public virtual string OznakaA {get;set;}
   public virtual string NazivA {get;set;}
}
public class TableB
{
   public virtual int ID {get;set;}
   public virtual TableA TableA {get;set;}
   public virtual string NazivB {get;set;}
}


ICriteria crit = session.CreateCrtieria(typeof(TableB));
crit.CreateAlias("TableA", "_TableA");
crit.Add(
   Expression.Sql( new SqlString( new object[] {
      "lower("_TableA.NazivA") like '%", searchString.ToLower(), "%'"
      
})));
// with the InsensitiveLikeExpression
//crit.Add(new InsensitiveLikeExpression("_TableA.NazivA", searchString.ToLower(), MatchMode.Anywhere));


In this format it will not work, the _TableA is not replaced with the NHibernate generated table SQL alias.
Is there a way to replace the _TableA with somthing like the {alias} option for the root criteria? Is there maybe some helper
class that does this? With the InsensitiveLikeExpression the _TableA is replaced with the SQL table alias
that NHibernate generates

I know that this simple query could be replaced with the InsensitiveLikeExpression,
i only used this as sample and I need the one with SQL.

Thx

[/code]


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.