Hello everyone,
today I have tricky Criteria query to make. Here is the HQL code:
this.Session.CreateQuery(@"select p
                                         from Product p
                                        where p.Name not in
                                              (select pc.Name from
ProductCategory pc where pc.Name like substring(p.Name, 0, 2) ) +
'%'")

Ok, I want to implement this in Criteria, but I have problem with
alias to the root entity. Because Expression.Like doesn,t support
aliased property values (?), there should be some Expression.Sql
solution. Here is the criteria query in which I cannot get the main
alias value. It seems that
http://216.121.112.228/browse/NH-1432?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel
should solve problem with aliases, but I still cannot get the alias:

Product productAlias = null;
 DetachedCriteria detachedCriteriaSubquery2 =
                DetachedCriteria.For<ProductCategory>()
                .CreateAlias<ProductCategory>(pc => pc.Products, () =>
productAlias)
                    .SetProjection(LambdaProjection.Property<ProductCategory>(x
=> x.Name))
                    .Add(Expression.Sql(new SqlString("CategoryName
like substring({productAlias}.Name, 0, 2) + '%'")));

            this.Session.CreateCriteria<Product>("p")
                .Add(LambdaSubquery.Property<Product>(x =>
x.Name).NotIn(detachedCriteriaSubquery2))
                .List<Product>();

Any clues how to get the Product "p" alias ? (Info: "like
substring({p}.Name, 0, 2)" doesn't work too).

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to