<html> <head> <META http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Deleting Structured Objects</title> <link rel="stylesheet" type="text/css" href="../../../style.css"> </head> <body> <div class="CommonContent"> <div class="CommonContentArea"> <h1>Deleting Structured Objects</h1><div id="TOC"><div id="TOCinner"><span class="TOCtitle">Contents</span><div class="TOCcontents"><ul><li><a href ="#Recursive Deletion ">Recursive Deletion </a></li><li><a href ="#Recursive Deletion Revisited">Recursive Deletion Revisited</a></li></ul></li></ul></div></div></div><script> //We attach this function to a browser object as a variable so that if multiple of these blocks are //present on the same page, then they will simply over-write eachother with the same function instead //of generating a naming collision. window.WikiCodeFormattingCopyToClipboard = function copyToClipboard(sID){ var sContent = document.getElementById(sID).innerText; if( window.clipboardData && clipboardData.setData ) { clipboardData.setData("Text", sContent); } else { alert("You must enable javascript access to your clipboard for this feature to work. Please referr to your browser documentation or Google search for instructions."); } } </script> <p>As we have already seen, we call delete() on objects to get rid of them.</p> <span name="cs_wiki_filter" csw_filters="cs"> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">StructuredExample.cs: <span class="fscMemberName">DeleteFlat</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteFlat_136_62"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">1</span><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> DeleteFlat(IObjectContainer db) </span><span style="color: #008080;">2</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteFlat_136_62_54_224_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteFlat_136_62_54_224_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteFlat_136_62_54_224_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteFlat_136_62_54_224_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteFlat_136_62_54_224_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteFlat_136_62_54_224_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteFlat_136_62_54_224_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteFlat_136_62_54_224_Open_Text').style.display='inline';"/> </span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteFlat_136_62_54_224_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteFlat_136_62_54_224_Open_Text"><span style="color: #000000;">{ </span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> IObjectSet result </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Car(</span><span style="color: #800000;">"</span><span style="color: #800000;">Ferrari</span><span style="color: #800000;">"</span><span style="color: #000000;">)); </span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> Car found </span><span style="color: #000000;">=</span><span style="color: #000000;"> (Car)result.Next(); </span><span style="color: #008080;">5</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> db.Delete(found); </span><span style="color: #008080;">6</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> result </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Car(</span><span style="color: #0000FF;">null</span><span style="color: #000000;">)); </span><span style="color: #008080;">7</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> ListResult(result); </span><span style="color: #008080;">8</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/> }</span></span></div></pre></div></div> <p>[/filter] </p> <p><span name="cs_wiki_filter" csw_filters="vb"></p> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">StructuredExample.vb: <span class="fscMemberName">DeleteFlat</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteFlat_275_62"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">1</span><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteFlat_275_62_15_309_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteFlat_275_62_15_309_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteFlat_275_62_15_309_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteFlat_275_62_15_309_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteFlat_275_62_15_309_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteFlat_275_62_15_309_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteFlat_275_62_15_309_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteFlat_275_62_15_309_Open_Text').style.display='inline';"/><span style="color: #0000FF;">Private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Shared</span><span style="color: #000000;"> </span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteFlat_275_62_15_309_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub DeleteFlat()</span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteFlat_275_62_15_309_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> DeleteFlat(</span><span style="color: #0000FF;">ByVal</span><span style="color: #000000;"> db </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectContainer) </span><span style="color: #008080;">2</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> result </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Car(</span><span style="color: #800000;">"</span><span style="color: #800000;">Ferrari</span><span style="color: #800000;">"</span><span style="color: #000000;">)) </span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> found </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Car </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">DirectCast</span><span style="color: #000000;">(result.Next(), Car) </span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> db.Delete(found) </span><span style="color: #008080;">5</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> result </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Car(</span><span style="color: #0000FF;">Nothing</span><span style="color: #000000;">)) </span><span style="color: #008080;">6</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> ListResult(result) </span><span style="color: #008080;">7</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/> </span><span style="color: #0000FF;">End Sub</span></span></div></pre></div></div> </span> <p>Fine, the car is gone. What about the pilots?</p> <span name="cs_wiki_filter" csw_filters="cs"> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">StructuredExample.cs: <span class="fscMemberName">RetrieveAllPilotsQBE</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilotsQBE_459_72"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">1</span><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> RetrieveAllPilotsQBE(IObjectContainer db) </span><span style="color: #008080;">2</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilotsQBE_459_72_64_167_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilotsQBE_459_72_64_167_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilotsQBE_459_72_64_167_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilotsQBE_459_72_64_167_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilotsQBE_459_72_64_167_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilotsQBE_459_72_64_167_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilotsQBE_459_72_64_167_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilotsQBE_459_72_64_167_Open_Text').style.display='inline';"/> </span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilotsQBE_459_72_64_167_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilotsQBE_459_72_64_167_Open_Text"><span style="color: #000000;">{ </span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> Pilot proto </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Pilot(</span><span style="color: #0000FF;">null</span><span style="color: #000000;">, </span><span style="color: #800080;">0</span><span style="color: #000000;">); </span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> IObjectSet result </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(proto); </span><span style="color: #008080;">5</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> ListResult(result); </span><span style="color: #008080;">6</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/> }</span></span></div></pre></div></div> <p></span> </p> <p><span name="cs_wiki_filter" csw_filters="vb"></p> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">StructuredExample.vb: <span class="fscMemberName">RetrieveAllPilotsQBE</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilotsQBE_606_72"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">1</span><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilotsQBE_606_72_15_224_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilotsQBE_606_72_15_224_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilotsQBE_606_72_15_224_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilotsQBE_606_72_15_224_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilotsQBE_606_72_15_224_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilotsQBE_606_72_15_224_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilotsQBE_606_72_15_224_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilotsQBE_606_72_15_224_Open_Text').style.display='inline';"/><span style="color: #0000FF;">Private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Shared</span><span style="color: #000000;"> </span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilotsQBE_606_72_15_224_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub RetrieveAllPilotsQBE()</span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilotsQBE_606_72_15_224_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> RetrieveAllPilotsQBE(</span><span style="color: #0000FF;">ByVal</span><span style="color: #000000;"> db </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectContainer) </span><span style="color: #008080;">2</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> proto </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Pilot(</span><span style="color: #0000FF;">Nothing</span><span style="color: #000000;">, </span><span style="color: #800080;">0</span><span style="color: #000000;">) </span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> result </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(proto) </span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> ListResult(result) </span><span style="color: #008080;">5</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/> </span><span style="color: #0000FF;">End Sub</span></span></div></pre></div></div> </span> <p>Ok, this is no real surprise - we don't expect a pilot to vanish when his car is disposed of in real life, too. But what if we want an object's children to be thrown away on deletion, too?</p> <a name="Recursive Deletion "></a><h2>Recursive Deletion </h2> <p>The problem of recursive deletion (and its solution, too) is quite similar to the <a href="updating_structured_objects.html" class="wikiLink">update</a> problem. Let's configure db4o to delete a car's pilot, too, when the car is deleted.</p> <span name="cs_wiki_filter" csw_filters="cs"> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">StructuredExample.cs: <span class="fscMemberName">DeleteDeepPart1</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart1_1208_67"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">1</span><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> IConfiguration DeleteDeepPart1() </span><span style="color: #008080;">2</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart1_1208_67_50_229_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart1_1208_67_50_229_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart1_1208_67_50_229_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart1_1208_67_50_229_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart1_1208_67_50_229_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart1_1208_67_50_229_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart1_1208_67_50_229_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart1_1208_67_50_229_Open_Text').style.display='inline';"/> </span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart1_1208_67_50_229_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart1_1208_67_50_229_Open_Text"><span style="color: #000000;">{ </span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> IConfiguration configuration </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4oFactory.NewConfiguration(); </span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> configuration.ObjectClass(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Car)).CascadeOnDelete(</span><span style="color: #0000FF;">true</span><span style="color: #000000;">); </span><span style="color: #008080;">5</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> configuration; </span><span style="color: #008080;">6</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/> }</span></span></div></pre></div></div> <p></span> </p> <p><span name="cs_wiki_filter" csw_filters="vb"></p> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">StructuredExample.vb: <span class="fscMemberName">DeleteDeepPart1</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart1_1350_67"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">1</span><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart1_1350_67_15_296_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart1_1350_67_15_296_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart1_1350_67_15_296_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart1_1350_67_15_296_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart1_1350_67_15_296_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart1_1350_67_15_296_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart1_1350_67_15_296_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart1_1350_67_15_296_Open_Text').style.display='inline';"/><span style="color: #0000FF;">Private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Shared</span><span style="color: #000000;"> </span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart1_1350_67_15_296_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Function DeleteDeepPart1()</span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart1_1350_67_15_296_Open_Text"><span style="color: #0000FF;">Function</span><span style="color: #000000;"> DeleteDeepPart1(</span><span style="color: #0000FF;">ByVal</span><span style="color: #000000;"> db </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectContainer) </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IConfiguration </span><span style="color: #008080;">2</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> configuration </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IConfiguration </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4oFactory.NewConfiguration() </span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> configuration.ObjectClass(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(Car)).CascadeOnDelete(</span><span style="color: #0000FF;">True</span><span style="color: #000000;">) </span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">Return</span><span style="color: #000000;"> configuration </span><span style="color: #008080;">5</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/> </span><span style="color: #0000FF;">End Function</span></span></div></pre></div></div> </span> <span name="cs_wiki_filter" csw_filters="cs"> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">StructuredExample.cs: <span class="fscMemberName">DeleteDeepPart2</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart2_1481_67"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">1</span><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> DeleteDeepPart2(IObjectContainer db) </span><span style="color: #008080;">2</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart2_1481_67_59_225_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart2_1481_67_59_225_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart2_1481_67_59_225_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart2_1481_67_59_225_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart2_1481_67_59_225_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart2_1481_67_59_225_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart2_1481_67_59_225_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart2_1481_67_59_225_Open_Text').style.display='inline';"/> </span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart2_1481_67_59_225_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepPart2_1481_67_59_225_Open_Text"><span style="color: #000000;">{ </span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> IObjectSet result </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Car(</span><span style="color: #800000;">"</span><span style="color: #800000;">BMW</span><span style="color: #800000;">"</span><span style="color: #000000;">)); </span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> Car found </span><span style="color: #000000;">=</span><span style="color: #000000;"> (Car)result.Next(); </span><span style="color: #008080;">5</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> db.Delete(found); </span><span style="color: #008080;">6</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> result </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Car(</span><span style="color: #0000FF;">null</span><span style="color: #000000;">)); </span><span style="color: #008080;">7</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> ListResult(result); </span><span style="color: #008080;">8</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/> }</span></span></div></pre></div></div> <p></span> </p> <p><span name="cs_wiki_filter" csw_filters="vb"></p> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">StructuredExample.vb: <span class="fscMemberName">DeleteDeepPart2</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart2_1623_67"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">1</span><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart2_1623_67_15_310_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart2_1623_67_15_310_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart2_1623_67_15_310_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart2_1623_67_15_310_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart2_1623_67_15_310_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart2_1623_67_15_310_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart2_1623_67_15_310_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart2_1623_67_15_310_Open_Text').style.display='inline';"/><span style="color: #0000FF;">Private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Shared</span><span style="color: #000000;"> </span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart2_1623_67_15_310_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub DeleteDeepPart2()</span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepPart2_1623_67_15_310_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> DeleteDeepPart2(</span><span style="color: #0000FF;">ByVal</span><span style="color: #000000;"> db </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectContainer) </span><span style="color: #008080;">2</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> result </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Car(</span><span style="color: #800000;">"</span><span style="color: #800000;">BMW</span><span style="color: #800000;">"</span><span style="color: #000000;">)) </span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> found </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Car </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">DirectCast</span><span style="color: #000000;">(result.Next(), Car) </span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> db.Delete(found) </span><span style="color: #008080;">5</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> result </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Car(</span><span style="color: #0000FF;">Nothing</span><span style="color: #000000;">)) </span><span style="color: #008080;">6</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> ListResult(result) </span><span style="color: #008080;">7</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/> </span><span style="color: #0000FF;">End Sub</span></span></div></pre></div></div> </span> <p>Again: Note that all configuration must take place before the ObjectContainer is opened.</p><p>Another way to organize cascaded deletion is using <a href="../../implementation_strategies/callbacks/possible_usecases/cascaded_behavior.html" class="wikiLink">callbacks</a>. The callbacks allow you to specify explicitly, which objects are to be deleted.<br></p> <a name="Recursive Deletion Revisited"></a><h2>Recursive Deletion Revisited</h2> <p>But wait - what happens if the children of a removed object are still referenced by other objects?</p> <span name="cs_wiki_filter" csw_filters="cs"> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">StructuredExample.cs: <span class="fscMemberName">DeleteDeepRevisited</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepRevisited_2245_71"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">01</span><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> DeleteDeepRevisited(IObjectContainer db) </span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepRevisited_2245_71_63_396_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepRevisited_2245_71_63_396_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepRevisited_2245_71_63_396_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepRevisited_2245_71_63_396_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepRevisited_2245_71_63_396_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepRevisited_2245_71_63_396_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepRevisited_2245_71_63_396_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepRevisited_2245_71_63_396_Open_Text').style.display='inline';"/> </span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepRevisited_2245_71_63_396_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_DeleteDeepRevisited_2245_71_63_396_Open_Text"><span style="color: #000000;">{ </span><span style="color: #008080;">03</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> IObjectSet result </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Pilot(</span><span style="color: #800000;">"</span><span style="color: #800000;">Michael Schumacher</span><span style="color: #800000;">"</span><span style="color: #000000;">, </span><span style="color: #800080;">0</span><span style="color: #000000;">)); </span><span style="color: #008080;">04</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> Pilot pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> (Pilot)result.Next(); </span><span style="color: #008080;">05</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> Car car1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Car(</span><span style="color: #800000;">"</span><span style="color: #800000;">Ferrari</span><span style="color: #800000;">"</span><span style="color: #000000;">); </span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> Car car2 </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Car(</span><span style="color: #800000;">"</span><span style="color: #800000;">BMW</span><span style="color: #800000;">"</span><span style="color: #000000;">); </span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> car1.Pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> pilot; </span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> car2.Pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> pilot; </span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> db.Set(car1); </span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> db.Set(car2); </span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> db.Delete(car2); </span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> result </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Car(</span><span style="color: #0000FF;">null</span><span style="color: #000000;">)); </span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> ListResult(result); </span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/> }</span></span></div></pre></div></div> <p></span> </p> <p><span name="cs_wiki_filter" csw_filters="vb"></p> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">StructuredExample.vb: <span class="fscMemberName">DeleteDeepRevisited</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepRevisited_2391_71"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">01</span><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepRevisited_2391_71_15_543_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepRevisited_2391_71_15_543_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepRevisited_2391_71_15_543_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepRevisited_2391_71_15_543_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepRevisited_2391_71_15_543_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepRevisited_2391_71_15_543_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepRevisited_2391_71_15_543_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepRevisited_2391_71_15_543_Open_Text').style.display='inline';"/><span style="color: #0000FF;">Private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Shared</span><span style="color: #000000;"> </span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepRevisited_2391_71_15_543_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub DeleteDeepRevisited()</span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_DeleteDeepRevisited_2391_71_15_543_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> DeleteDeepRevisited(</span><span style="color: #0000FF;">ByVal</span><span style="color: #000000;"> db </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectContainer) </span><span style="color: #008080;">02</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> result </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Pilot(</span><span style="color: #800000;">"</span><span style="color: #800000;">Michael Schumacher</span><span style="color: #800000;">"</span><span style="color: #000000;">, </span><span style="color: #800080;">0</span><span style="color: #000000;">)) </span><span style="color: #008080;">03</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> pilot </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">DirectCast</span><span style="color: #000000;">(result.Next(), Pilot) </span><span style="color: #008080;">04</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> car1 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Car </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Car(</span><span style="color: #800000;">"</span><span style="color: #800000;">Ferrari</span><span style="color: #800000;">"</span><span style="color: #000000;">) </span><span style="color: #008080;">05</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> car2 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> Car </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Car(</span><span style="color: #800000;">"</span><span style="color: #800000;">BMW</span><span style="color: #800000;">"</span><span style="color: #000000;">) </span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> car1.Pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> pilot </span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> car2.Pilot </span><span style="color: #000000;">=</span><span style="color: #000000;"> pilot </span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> db.Set(car1) </span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> db.Set(car2) </span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> db.Delete(car2) </span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> result </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">New</span><span style="color: #000000;"> Car(</span><span style="color: #0000FF;">Nothing</span><span style="color: #000000;">)) </span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> ListResult(result) </span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/> </span><span style="color: #0000FF;">End Sub</span></span></div></pre></div></div> </span> <span name="cs_wiki_filter" csw_filters="cs"> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">StructuredExample.cs: <span class="fscMemberName">RetrieveAllPilots</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilots_2526_69"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">1</span><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/None.gif" align="top"/><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">static</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> RetrieveAllPilots(IObjectContainer db) </span><span style="color: #008080;">2</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilots_2526_69_62_138_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilots_2526_69_62_138_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilots_2526_69_62_138_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilots_2526_69_62_138_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilots_2526_69_62_138_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilots_2526_69_62_138_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilots_2526_69_62_138_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilots_2526_69_62_138_Open_Text').style.display='inline';"/> </span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilots_2526_69_62_138_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredCS.ZipsStructuredExample.Cs_StructuredExample.Cs_RetrieveAllPilots_2526_69_62_138_Open_Text"><span style="color: #000000;">{ </span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> IObjectSet results </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Pilot)); </span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> ListResult(results); </span><span style="color: #008080;">5</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/> }</span></span></div></pre></div></div> <p></span> </p> <p>[filter=vb]</p> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">StructuredExample.vb: <span class="fscMemberName">RetrieveAllPilots</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilots_2636_69"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">1</span><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilots_2636_69_15_177_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilots_2636_69_15_177_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilots_2636_69_15_177_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilots_2636_69_15_177_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilots_2636_69_15_177_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilots_2636_69_15_177_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilots_2636_69_15_177_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilots_2636_69_15_177_Open_Text').style.display='inline';"/><span style="color: #0000FF;">Private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Shared</span><span style="color: #000000;"> </span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilots_2636_69_15_177_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub RetrieveAllPilots()</span><span id="ResourcesReferenceObject_LifecycleWorking_With_Structured_ObjectsstructuredVB.ZipsStructuredExample.Vb_StructuredExample.Vb_RetrieveAllPilots_2636_69_15_177_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> RetrieveAllPilots(</span><span style="color: #0000FF;">ByVal</span><span style="color: #000000;"> db </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectContainer) </span><span style="color: #008080;">2</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> results </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Get(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(Pilot)) </span><span style="color: #008080;">3</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> ListResult(results) </span><span style="color: #008080;">4</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/> </span><span style="color: #0000FF;">End Sub</span></span></div></pre></div></div> </span> <p>Currently db4o does <b>not</b> check whether objects to be deleted are referenced anywhere else, so please be very careful when using this feature.However it is fairly easy to implement referential checking on deletion using deleting() callback. See <a href="../../implementation_strategies/callbacks.html" class="wikiLink">Callbacks chapter</a> for more information.</p></div> </div> <div id="footer"> This revision (10) was last Modified 2007-05-07T08:05:57 by Tetyana. </div> </body> </html>