I've implemented this code in order to obtain the stock of a concrete day.
The problem resides in
[/code]
Code:
NHibernate.ISQLQuery query = (NHibernate.ISQLQuery)session.CreateSQLQuery("SELECT {stock.Article.*}, {stock.Site.*}, SUM(QUANTITY) AS {stock.Quantity} " +
"FROM ( " +
"SELECT ARTICLE_ID, TO_PLACE_ID SITE,
if I write -->
[/code]
Code:
NHibernate.ISQLQuery query = (NHibernate.ISQLQuery)session.CreateSQLQuery("SELECT {stock.*} " +
"FROM ( " +
"SELECT ARTICLE_ID, TO_PLACE_ID SITE,
, the result is correct. However, I need to apply SUM grouping to QUANTITY field.
Code:
IList<Model.Consulting.Stock> result = new List<Model.Consulting.Stock>();
NHibernate.ISession session = this.session_factory.OpenSession();
NHibernate.ISQLQuery query = (NHibernate.ISQLQuery)session.CreateSQLQuery("SELECT {stock.Article.*}, {stock.Site.*}, SUM(QUANTITY) AS {stock.Quantity} " +
"FROM ( " +
"SELECT ARTICLE_ID, TO_PLACE_ID SITE, CAST(AMOUNT AS SIGNED INT) QUANTITY " +
"FROM STOCK_MOVEMENTS WHERE TO_PLACE_ID IS NOT NULL AND MOVEMENT_DATE < ? " +
"UNION ALL " +
"SELECT ARTICLE_ID, FROM_PLACE_ID SITE, CAST(-AMOUNT AS SIGNED INT) QUANTITY " +
"FROM STOCK_MOVEMENTS " +
"WHERE FROM_PLACE_ID IS NOT NULL AND MOVEMENT_DATE < ? " +
") stock " +
"GROUP BY ARTICLE_ID, SITE").AddEntity("stock", typeof(Model.Consulting.Stock)).SetDateTime(0, date).SetDateTime(1, date);
result = query.List<Model.Consulting.Stock>();
session.Close();
return result;
As you can see I need obtain a list of Model.Consulting.Stock objects which in each one cotains a Place Object, Article Object and Quantity.
Can you help me please?
Thansk for all.