-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Criteria Help
PostPosted: Tue May 26, 2009 5:14 pm 
Newbie

Joined: Tue May 26, 2009 5:07 pm
Posts: 1
I am trying to do the following SQL query:

Code:
SELECT     oi.ProductCode, SUM(oi.OrderQty) AS OrderQty, prod.Description, prod.Price, prod.QtyOnHand, SUM(oi.OrderQty * prod.Price) AS ItemTotal
FROM         OrderItems AS oi INNER JOIN
                      Orders AS ord ON oi.OrderId = ord.OrderId INNER JOIN
                      Products AS prod ON oi.ProductId = prod.Id
WHERE     (ord.OrderDate BETWEEN '01/01/2008' AND '09/01/2009')
GROUP BY oi.ProductCode, prod.Description, prod.Price, prod.QtyOnHand
ORDER BY oi.ProductCode


as a Criteria query, but I haven't been able to get it to run successfully.

As it is now:

Code:
return CreateCriteria("oi")
                .CreateCriteria("oi.Order", "o")
                .CreateCriteria("oi.Product", "p", JoinType.FullJoin)
                .Add(Expression.Conjunction()
                    .Add(Expression.Eq("order.OrderType", "Sale"))
                    .Add(Expression.Between("order.OrderDate", DateTime.Parse(startDate.ToShortDateString()), DateTime.Parse(endDate.ToShortDateString())))
                )
                .SetProjection(Projections.ProjectionList()
                        .Add(Projections.GroupProperty("p.ProductCode"))
                        .Add(Projections.GroupProperty("p.Description")))
                .AddOrder(NHibernate.Criterion.Order.Asc("p.ProductCode"))
                .List<OrderItem>();


I get this error and can't make any sense of it:

The value "System.Object[]" is not of type "EcoStore.Domain.OrderItem" and cannot be used in this generic collection.
Parameter name: value

Can anyone point me in the right direction?


Top
 Profile  
 
 Post subject: Re: Criteria Help
PostPosted: Wed May 27, 2009 4:09 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Code:
CreateCriteria("oi")
                .CreateCriteria("oi.Order", "o")
                .CreateCriteria("oi.Product", "p", JoinType.FullJoin)


.CreateCriteria returns a subcriteria. In your case you try to join Product to Order. Try this instead:

Code:
CreateCriteria("oi")
                .CreateAlias("oi.Order", "o")
                .CreateAlias("oi.Product", "p", JoinType.FullJoin)

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.