Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1036791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:45:42+00:00 2026-05-16T14:45:42+00:00

I’m having alot of trouble with my code. When I compile I get the

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:45:43+00:00Added an answer on May 16, 2026 at 2:45 pm

    You’re trying to implement the non-generic IEnumerable type too, as IEnumerable<T> extends it. Fortunately, this is easy:

    // Along with the existing using directives
    using System.Collections;
    ...
    
    // In the implementing class
    IEnumerator IEnumerable.GetEnumerator()
    {
        return GetEnumerator();
    }
    

    Note that you have to use explicit interface implementation for at least one of the two GetEnumerator() methods you need to implement, as they have the same signature (same name, no parameters) but different return types. Fortunately, the return value of the generic version is fine to use for the non-generic version, which is why the above pattern is usually used.

    EDIT: As Josh correctly notes in the comments, you have other problems too:

    • You shouldn’t have a return list; at the end of your code, unless you remove the yield break; earlier (and change it to return list.GetEnumerator();). If you want to keep your code as an iterator block, you should be using yield return to yield each node you create.
    • You should be yielding instances of T – whereas you’re constructing instances of ProductNode. Perhaps you should actually be implementing IEnumerable<ProductNode> instead of IEnumerable<T>, and make your class non-generic?
    • Your code will keep the SQL connection open for as long as the caller decides to take iterating over it. That may or may not be a problem – but it’s worth bearing in mind.
    • You should use a using statement to make sure that your nodeReader is disposed on error (assuming the caller disposes of the IEnumerator<T> of course)
    • Your public list field is a bad idea… why have you made it an instance variable at all?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
Does anyone know how can I replace this 2 symbol below from the string
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.