How about using HQL? Is it possible.

On Mon, Jul 6, 2009 at 4: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_toksoz
> http://tunatoksoz.com
> http://twitter.com/tehlike
>
>
>
>
> On Mon, Jul 6, 2009 at 8:23 AM, zhibin <[email protected]> wrote:
>>
>> I have the following 2 classes:
>>
>> public abstract class AbstractProduct : Entity
>> {
>>        public virtual ISet<Price> Prices { get; set; }
>> }
>>
>> public class Price : Entity
>> {
>>        public virtual AbstractProduct AbstractProduct { get; set; }
>>        public virtual decimal Amount { get; set; }
>>        public virtual decimal Quantity { get; set; }
>>        public virtual DateTime? Expires {get; set;}
>> }
>>
>> I want to get products ordered by unit price.  The SQL I supposed is:
>>            select p0.*, (select min(pr.amount) from "Price" pr
>>                            where pr.abstractproduct_id=p0.id
>>                                and pr.Quantity = 1
>>                                and (pr.expires>'2009-7-1' or
>> pr.expires is null)
>>                            )as amount
>>            from "AbstractProduct" p0;
>>            order by amount;
>>
>> I tried it in Postgresql, it returns correct result. but I don't know
>> how to code it with the Criteria API.
>>
>> Can anybody help me?
>> Thanks!
>>
>
>
> >
>

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