troubleshooting Question

Update child object reference

Avatar of Dinesh Bali
Dinesh Bali asked on
5 Comments1 Solution89 ViewsLast Modified:

I have object called productbzAux  and it product type has value "A". I wanted to duplicate the same product with productType as "C" and add it to the same List object productCategoryBEList

My below code is updating the productType for parent and child object i.e., productbzAux  and productbzCore

Also, please advise the best way to write the below code.

The below code is in C#


List<ProductCategoryBE> productCategoryBEList = shoppingCartBE.ArrivalBooking.AvailableProducts;

            if (productCategoryBEList != null)
                ProductCategoryBE productCategoryAUXBE = productCategoryBEList.FirstOrDefault(p => p.CategoryCode.ToUpper().Contains("AUX"));
                ProductItem productbzAux = productCategoryAUXBE.Products.FirstOrDefault(t => t.SubCategoryCode.ToUpper().Contains("bz"));

                if (productbzAux != null)
                    List<ProductItem> products = productCategoryAUXBE.Products;
                    ProductItem productbzCore = new ProductItem();
                    productbzCore = productbzAux;
                    productbzCore.ProductType = "C"; // This is updating the ProductType of parent object i.e., productbzAux.ProductType where as it should be A for parent and C for child.

                    productCategoryAUXBE.Products = products;


Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros