IEnumerator seems to be effecting all objects, and not one at a time

Posted by PFranchise on Stack Overflow See other posts from Stack Overflow or by PFranchise
Published on 2010-06-09T21:53:48Z Indexed on 2010/06/09 22:12 UTC
Read the original article Hit count: 166

Filed under:
|
|

Hey, I am trying to alter an attribute of an object. I am setting it to the value of that same attribute stored on another table. There is a one to many relationship between the two. The product end is the one and the versions is the many. Right now, both these methods that I have tried have set all the products returned equal to the final version object. So, in this case they are all the same. I am not sure where the issue lies. Here are my two code snipets, both yield the same result.

            int x = 1
            IEnumerator<Product> ie = productQuery.GetEnumerator();
            while (ie.MoveNext())
            {
                ie.Current.RSTATE = ie.Current.Versions.First(o => o.VersionNumber == x).RSTATE;
                x++;
            }

and

             foreach (var product in productQuery)
            {

                product.RSTATE = product.Versions.Single(o => o.VersionNumber == x).RSTATE;
                x++;
            }

The versions table holds information for previous products, each is distinguished by the version number. I know that it will start at 1 and go until it reaches the current version, based on my query returning the proper number of products.

Thanks for any advice.

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET