Thank you for your reply.
I like the VarArgsSQLFunction better because I actually figured out
how to use it :)
I didn't really finish this query yet.
What I have is:
ISQLFunction arithmeticMulti = new VarArgsSQLFunction("(",
"*", ")");
DetachedCriteria orderitems =
DetachedCriteria.For(typeof(OrderItem))
.SetProjection(
Projections.ProjectionList()
.Add(Projections.Sum(Projections.SqlFunction(arithmeticMulti,
NHibernateUtil.GuessType(typeof (decimal)),
Projections.Property("Price"), Projections.Property("Quantity"))),
"OrderAmmount")
.Add(Projections.GroupProperty("Order.Id"),
"Id")
)
//.Add(Expression.Ge("OrderAmmount", ammount)) //fails-
NHibernate.QueryException : Could not find property OrderAmmount
//.SetResultTransformer(Transformers.AliasToBean(typeof(OrderTTable))) //
doesn't help (of course,it being 'client side')
;
var list =
_session.CreateCriteria<Customer>().CreateCriteria("Orders").Add(Subqueries.PropertyIn("Id",
orderitems)).List<Customer>();
return list;
Now, the query fails, with a SQL error: 'Only one expression can be
specified in the select list when the subquery is not introduced with
EXISTS.'
How can I correct my method to make the query produce the desired SQL?
Also, I still didn't find a place to add that '> ammount' restriction.
So, I get this SQL:
SELECT
this_.CUSTOMER_ID as CUSTOMER1_0_1_,
this_.Name as Name0_1_,
this_.PIN as PIN0_1_,
order1_.ORDER_ID as ORDER1_1_0_,
order1_.Nr as Nr1_0_,
order1_.[Date] as Date3_1_0_,
order1_.CUSTOMER_ID as CUSTOMER4_1_0_
FROM CUSTOMERS this_ inner join ORDERS order1_ on
this_.CUSTOMER_ID=order1_.CUSTOMER_ID
WHERE order1_.ORDER_ID in
(
SELECT sum((this_0_.Price*this_0_.Quantity)) as y0_,
this_0_.ORDER_ID as y1_
FROM ORDERITEMS this_0_
GROUP BY this_0_.ORDER_ID
)
and I would like to get this I guess
SELECT
this_.CUSTOMER_ID as CUSTOMER1_0_1_,
this_.Name as Name0_1_,
this_.PIN as PIN0_1_,
order1_.ORDER_ID as ORDER1_1_0_,
order1_.Nr as Nr1_0_,
order1_.[Date] as Date3_1_0_,
order1_.CUSTOMER_ID as CUSTOMER4_1_0_
FROM [Test].[dbo].[CUSTOMERS] this_ inner join [Test].[dbo].[ORDERS]
order1_ on this_.CUSTOMER_ID=order1_.CUSTOMER_ID
WHERE order1_.ORDER_ID in
(
select A.y1_
from
(
SELECT sum((this_0_.Price*this_0_.Quantity)) as y0_, this_0_.ORDER_ID
as y1_
FROM [Test].[dbo].[ORDERITEMS] this_0_
GROUP BY this_0_.ORDER_ID
) A where A.y0_ > @ammount
)
I think I should add an alias somewhere but I don't know where or how.
Thanks again.
--
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.