views:

48

answers:

2

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.

+1  A: 
Joel Coehoorn
I appreciate the response. I altered my code to match yours, but it did not resolve the issue.
PFranchise
Hm, I am still new to this, so I am sure there might be an easier way to do this, but I am not sure what that would be. I will look into .select() and see if that can help.
PFranchise
O, were you talking about altering my original query? Sorry, might be a dumb question, but that is the only select that I am currently aware of.Edit: Nevermind, I think I see what you mean. Doing something like product.select().
PFranchise
A: 

Ok, so apparently it is altering all of them because product has a unique Identity column, so when I modify one instance of it, it changes them all. So, looks like it is back to the drawing board.

PFranchise