Hello forum, I've a doubt because I don't know how translate a query to list of objects.
I have a Stock object as -->
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
}
And I need to execute this sentence-->
Code:
SELECT ARTICLE_ID, TO_PLACE_ID SITE, CAST(AMOUNT AS SIGNED INT) QUANTITY FROM STOCK_MOVEMENTS WHERE TO_PLACE_ID IS NOT NULL
How Can I translate the result sentence to list of Stock objects?
I will appreciate very much your help.
Thanks for all in advanced.