Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Deleting child entities inside parent / child relationsh
Message
From
30/06/2008 17:45:35
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
30/06/2008 17:26:42
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
01327749
Message ID:
01327752
Views:
9
Hi Tim,

There seems to be some stuff missing, have you stepped through this in the debugger?

You are registering the details as a child and calling a method to retrieve the order header, but not the details. Plus you have set the entity object directly. I would have thought to see something like this:
oOrder = (Order)this.registerBizObj(new Order());
oDetails = (OrderDetails)this.registerBizObj(new OrderDetails());
oOrder.RegisterChildBizObj(this.oDetails);

// This will retrieve the order header
oOrder.GetOrderByOrderID(10251);
// This will retrieve the detail items.
oDetails.GetDetailsByOrderID(this.oOrder.Entity.OrderID);

// Then when you delete the first line all you have done is removed it from the list.
// You could call an actual delete method
Tim

>
>I am having problems figuring out deleting entities from a child list with parent. I have tried this using the Order - Order Details objects from the Jump Start.
>
>Here is some test code.
>
>
>   [Test]
>        public void TestOrderDetails()
>        {
>            // create a new order header
>            Order theOrder = new Order();
>
>            OrderDetail theDetails = new OrderDetail();
>
>            theOrder.RegisterChildBizObj(theDetails);
>
>            theOrder.Entity = theOrder.GetOrderByOrderID(10251);
>
>            Console.Out.WriteLine("Details for Order: " + theOrder.Entity.OrderID.ToString() + " - " + theOrder.Entity.OrderDate.ToString());
>
>            foreach (OrderDetailEntity detail in theDetails.EntityList)
>            {
>                Console.Out.WriteLine(detail.ProductID.ToString());
>            }
>
>            // delete the first detail line from the details entity list.
>
>            theDetails.EntityList.RemoveAt(0);
>
>            mmSaveDataResult saveResult = theOrder.SaveEntity();
>
>            if(saveResult == mmSaveDataResult.RulesBroken)
>            {
>                Console.Error.WriteLine(theOrder.Rules.GetAllBrokenRules());
>            }
>
>            Assert.That(saveResult != mmSaveDataResult.RulesBroken,"Error saving order!");
>
>            // load the the details back from the server to see if deleted
>
>            theOrder = new Order();
>
>            theDetails = new OrderDetail();
>
>            theOrder.RegisterChildBizObj(theDetails);
>
>            theOrder.Entity = theOrder.GetOrderByOrderID(10251);
>
>            Console.Out.WriteLine("Details for Order: " + theOrder.Entity.OrderID.ToString() + " - " + theOrder.Entity.OrderDate.ToString());
>
>            foreach (OrderDetailEntity detail in theDetails.EntityList)
>            {
>                Console.Out.WriteLine(detail.ProductID.ToString());
>            }
>        }
>
>    }
>
>
>
>
>
>The code executes without errors, but the row deleted from the entity list is not deleted from the table.
>
>What am I missing?
>
>Thanks
>
>Tim Holgerson
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform