I tested the code you provided, the generated SQL is like:
SELECT this_.Id as Id0_0_, this_.Sku as Sku0_0_, ...
FROM "AbstractProduct" this_
ORDER BY (SELECT min(this_0_.Amount) as y0_
FROM "Price" this_0_
WHERE this_0_.AbstractProduct_id = this_.Id and
this_0_.Quantity = :p0 and (this_0_.Expires > :p1 or this_0_.Expires
is null)) asc
it solved my problem. thanks very much!
I have one more questions:
is the performance of the above SQL statement the same as:
SELECT this_.Id as Id0_0_, this_.Sku as Sku0_0_, ..., (SELECT min
(this_0_.Amount) as y0_ FROM "Price" ...) amount
FROM "AbstractProduct" this_
ORDER BY amount asc
I am not good of SQL, please forgive me for this naive question.
On Jul 6, 2:34 pm, Tuna Toksoz <[email protected]> wrote:
> Unfortunately, this part is not possible
>
> p0.*,
>
> We don't have "entity" projection in Criteria.but we can order by it, if it
> works.
> var amount=DetachedCriteria.For(typeof(Price),"pr")
>
> .Add(Restrictions.EqProperty("pr.AbstractProductId","p0.abstractproduct_id"))
>
> .Add(Restrictions.Eq("pr.Quantity",1))
>
> .Add(Restrictions.Eq("pr.Expires"),new DateTime(2009,7,1));
>
> .SetProjection(Projections.Min("pr.Amoun"));
> var crit=session.CreateCriteria(typeof(AbstractProduct),"p0").
> .AddOrder(
> Order.Asc(Projections.Subquery(amount));
>
> Tuna Toksöz
> Eternal sunshine of the open source mind.
>
> http://devlicio.us/blogs/tuna_toksozhttp://tunatoksoz.comhttp://twitter.com/tehlike
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---