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]