Hi,
I'm having alot of trouble with my code. When I compile I get the following error:
'Ecommerce.DataHelpers.ProductNodeLoader' does not implement interface member 'System.Collections.IEnumerable.GetEnumerator()'. 'Ecommerce.DataHelpers.ProductNodeLoader.GetEnumerator()' cannot implement 'System.Collections.IEnumerable.GetEnumerator()' because it does not have the matching return type of 'System.Collections.IEnumerator'.
Im not sure how to solve this so now I have to ask you guys!
CODE:
namespace Ecommerce.DataHelpers
{
public class ProductNodeLoader<T> : IEnumerable<T>
{
private ISqlHelper sqlHelper;
private IRecordsReader nodeReader;
public List<T> list = new List<T>();
// load all products from given company
public IEnumerator<T> GetEnumerator()
{
int companyId = 2;
try
{
sqlHelper = DataLayerHelper.CreateSqlHelper(GlobalSettings.DbDSN);
nodeReader = sqlHelper.ExecuteReader(@"
SELECT * FROM eCommerceNodes WHERE companyId = @companyId)
", sqlHelper.CreateParameter("@companyId", companyId));
}
catch (Exception e)
{
Log.Add(LogTypes.Custom, -1, e.InnerException.ToString());
yield break;
}
if (nodeReader.HasRecords)
{
while(nodeReader.Read())
{
ProductNode node = new ProductNode();
node.id = nodeReader.Get<int>("id");
node.parentId = nodeReader.Get<int>("parentId");
node.companyId = nodeReader.Get<int>("companyId");
node.path = nodeReader.Get<string>("path");
node.sortOrder = nodeReader.Get<string>("sortOrder");
node.text = nodeReader.Get<string>("text");
node.nodeType = nodeReader.Get<int>("nodeType");
list.Add(node);
}
nodeReader.Close();
}
else
{
throw new ApplicationException("No products to load");
}
return list;
}
}
}
I apologize for the bad editing!