For every ProductSpecificationAttribute in OrderItems

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
4 years ago
Hello!  What if I need to iterate throught every ProductSpecificationAttribute in an order?  The following code fails because OrderItem does not have GetEnumerator.


foreach (OrderItem item in order.OrderItems)
            {
                foreach (ProductSpecificationAttribute spec in item)
                {

                }
            }


Thanks!

Jeremy
4 years ago
Hi Jeremy,

You can iterate through an enumerator but, order item isn't enumerator. Besides that, ProductSpecificationAttribute collection is a member of the product entity class, not order item. So, your code should look like this:

foreach (OrderItem item in order.OrderItems)
{
    foreach (ProductSpecificationAttribute spec in item.Product.ProductSpecificationAttributes)
    {

    }
}
4 years ago
resanehlab wrote:
Hi Jeremy,

You can iterate through an enumerator but, order item isn't enumerator. Besides that, ProductSpecificationAttribute collection is a member of the product entity class, not order item. So, your code should look like this:

foreach (OrderItem item in order.OrderItems)
{
    foreach (ProductSpecificationAttribute spec in item.Product.ProductSpecificationAttributes)
    {

    }
}


resanehlab, that works perfectly.  Thanks for the clarity.

Have an excellent day!

Jeremy
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.