I need to obtain a list of Stock Objects, and I use a native SQL in order to obtain this list -->
Code:
NHibernate.ISession session = this.session_factory.OpenSession();
NHibernate.ISQLQuery query = session.CreateSQLQuery("SELECT A.* {stock.Id.Article.*}, P.* {stock.Id.Place.*}, CAST(AMOUNT AS SIGNED INT) {stock.Amount} " +
"FROM STOCK_MOVEMENTS M, ARTICLE A {stock.Id.Article}, PLACE P {stock.Id.Place} WHERE M.TO_PLACE_ID IS NOT NULL").AddEntity("stock", typeof(Model.Consulting.Stock));
return query.List<Model.Consulting.Stock>();
The exception message is -->
Quote:
No column name found for property [Id.Article.*] for alias [stock] [SELECT A.* {stock.Id.Article.*}, P.* {stock.Id.Place.*}, CAST(AMOUNT AS SIGNED INT) {stock.Amount} FROM STOCK_MOVEMENTS M, ARTICLE A {stock.Id.Article}, PLACE P {stock.Id.Place} WHERE M.TO_PLACE_ID IS NOT NULL]
Code:
public class Stock
{
private Model.Consulting.StockId id;
private int quantity;
protected Stock () {
this.id = new StockId();
this.quantity = -1;
}
public Stock(Model.Entities.ComplexArticle article, Model.Entities.Place site, int quantity)
{
this.id = new StockId(article, site);
this.quantity = quantity;
}
#region Properties
public virtual Model.Consulting.StockId Id { get { return id; } set { id = value; } }
public virtual Model.Entities.ComplexArticle Article { get { return this.id.Article; } set { this.id.Article = value; } }
public virtual Model.Entities.Place Site { get { return this.id.Site; } set { this.id.Site = value; } }
public virtual int Quantity { get { return quantity; } set { quantity = value; } }
public virtual double Value { get { return this.id.Article.Price * this.quantity; } }
#endregion
}
public class StockId
{
private Model.Entities.ComplexArticle article;
private Model.Entities.Place site;
public StockId()
{
this.article = null;
this.site = null;
}
public StockId(Model.Entities.ComplexArticle article, Model.Entities.Place site)
{
this.article = article;
this.site = site;
}
#region Properties
public virtual Model.Entities.ComplexArticle Article { get { return article; } set { article = value; } }
public virtual Model.Entities.Place Site { get { return site; } set { site = value; } }
#endregion
#region ToString, Equals, HashCode
public override bool Equals(object obj)
{
if (this == obj) return true;
if (obj == null || !obj.GetType().Equals(this.GetType())) return false;
Model.Consulting.StockId altre = (Model.Consulting.StockId)obj;
return this.Article == altre.Article && this.Site == altre.Site;
}
public override int GetHashCode()
{
return this.Site.GetHashCode() + this.Article.GetHashCode() + 74;
}
#endregion
}
I don't how to create this sentence.
Can you help me, please.
I will appreciate a lot your help.
Thanks for all.