Hello everyone,

I have a subquery connected with the outer query as follows:
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) ) +
'%'").

I would like to rewrite it to the criteria API. I tried to make
reference to the Product in subquery by alias, but it don't want to
work:

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

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

Can anyone find the solution? Or rewrite this query in other way?

regards
Kamil Kliczbor

-- 
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