Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 864d1c3c3cd8df4e3a2692faf8776e05 > files > 828

db4o-doc-7.4-2.fc13.i686.rpm

<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Deleting Collections</title>
    <link rel="stylesheet" type="text/css" href="../../../style.css">
  </head>
  <body>
    <div class="CommonContent">
      <div class="CommonContentArea">
        <h1>Deleting Collections</h1><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 it was discussed in
<a href="../working_with_structured_objects/deleting_structured_objects.html" class="wikiLink">Deleting Structured Objects</a> chapter,
deleting a top-level object does not mean deleting all of the member objects.
The same rule applies for collections. The recommendation would be to use
cascadeOnDelete setting for a collection, which should be deleted with all its
members.</p><p>For the following example we will use <a href="example_classes.html" class="wikiLink">DataObject and
ListObject</a> classes. The database will be filled up with the
<a href="filling_the_database.html" class="wikiLink">FillUpDb</a> method. <br></p>

<span name="cs_wiki_filter" csw_filters="cs">

<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">ListDeletingExample.cs: <span class="fscMemberName">DeleteTest</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_32_1354_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_32_1354_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_32_1354_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_32_1354_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_32_1354_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_32_1354_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_32_1354_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_32_1354_Open_Text').style.display='inline';"/><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;"> DeleteTest()</span><span id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_32_1354_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_32_1354_Open_Text"><span style="color: #000000;">{
</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: #008000;">//</span><span style="color: #008000;"> set cascadeOnDelete in order to delete member objects</span><span style="color: #008000;">
</span><span style="color: #008080;">03</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">            IConfiguration configuration </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4oFactory.NewConfiguration();
</span><span style="color: #008080;">04</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;">(ListObject)).CascadeOnDelete(</span><span style="color: #0000FF;">true</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"/>            IObjectContainer db </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4oFactory.OpenFile(configuration , Db4oFileName);
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">try</span><span style="color: #000000;">
</span><span style="color: #008080;">07</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_373_745_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_373_745_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_373_745_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_373_745_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_373_745_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_373_745_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_373_745_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_373_745_Open_Text').style.display='inline';"/>            </span><span id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_373_745_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_373_745_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                IList</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">ListObject</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> result </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Query</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">ListObject</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(ListObject));
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (result.Count </span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">0</span><span style="color: #000000;">)
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_514_731_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_514_731_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_514_731_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_514_731_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_514_731_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_514_731_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_514_731_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_514_731_Open_Text').style.display='inline';"/>                </span><span id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_514_731_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_514_731_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                  </span><span style="color: #008000;">//</span><span style="color: #008000;"> retrieve a ListObject</span><span style="color: #008000;">
</span><span style="color: #008080;">12</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    ListObject lo1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> result[</span><span style="color: #800080;">0</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"/>                    </span><span style="color: #008000;">//</span><span style="color: #008000;"> delete the ListObject with all the field objects</span><span style="color: #008000;">
</span><span style="color: #008080;">14</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    db.Delete(lo1);
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>                }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_754_794_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_754_794_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_754_794_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_754_794_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_754_794_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_754_794_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_754_794_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_754_794_Open_Text').style.display='inline';"/>            }</span></span><span style="color: #000000;"> </span><span style="color: #0000FF;">finally</span><span style="color: #000000;"> </span><span id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_754_794_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_754_794_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              db.Close();
</span><span style="color: #008080;">18</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>            }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">19</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #008000;">//</span><span style="color: #008000;"> check ListObjects and DataObjects in the database</span><span style="color: #008000;">
</span><span style="color: #008080;">20</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">            db </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4oFactory.OpenFile(Db4oFileName);
</span><span style="color: #008080;">21</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_929_1292_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_929_1292_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_929_1292_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_929_1292_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_929_1292_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_929_1292_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_929_1292_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_929_1292_Open_Text').style.display='inline';"/>            </span><span style="color: #0000FF;">try</span><span style="color: #000000;"> </span><span id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_929_1292_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_929_1292_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">22</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              IList</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">ListObject</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> listObjects </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Query</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">ListObject</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(ListObject));
</span><span style="color: #008080;">23</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>              Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">ListObjects in the database:  </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> listObjects.Count);
</span><span style="color: #008080;">24</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                IList</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">DataObject</span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> dataObjects </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Query</span><span style="color: #000000;">&lt;</span><span style="color: #000000;">DataObject</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(DataObject));
</span><span style="color: #008080;">25</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">DataObjects in the database: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> dataObjects.Count);
</span><span style="color: #008080;">26</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_1301_1344_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_1301_1344_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_1301_1344_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_1301_1344_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_1301_1344_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_1301_1344_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_1301_1344_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_1301_1344_Open_Text').style.display='inline';"/>          }</span></span><span style="color: #000000;"> </span><span style="color: #0000FF;">finally</span><span style="color: #000000;"> </span><span id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_1301_1344_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingCS.ZipsListDeletingExample.Cs_ListDeletingExample.Cs_DeleteTest_594_66_1301_1344_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">27</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Close();
</span><span style="color: #008080;">28</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top"/>            }</span></span><span style="color: #000000;">
</span><span style="color: #008080;">29</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockEnd.gif" align="top"/>        }</span></span></div></pre></div></div>

</span><span name="cs_wiki_filter" csw_filters="vb">


<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">ListDeletingExample.vb: <span class="fscMemberName">DeleteTest</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingVB.ZipsListDeletingExample.Vb_ListDeletingExample.Vb_DeleteTest_722_66"><div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><span style="color: #008080;">01</span><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingVB.ZipsListDeletingExample.Vb_ListDeletingExample.Vb_DeleteTest_722_66_15_1418_Open_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingVB.ZipsListDeletingExample.Vb_ListDeletingExample.Vb_DeleteTest_722_66_15_1418_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingVB.ZipsListDeletingExample.Vb_ListDeletingExample.Vb_DeleteTest_722_66_15_1418_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingVB.ZipsListDeletingExample.Vb_ListDeletingExample.Vb_DeleteTest_722_66_15_1418_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingVB.ZipsListDeletingExample.Vb_ListDeletingExample.Vb_DeleteTest_722_66_15_1418_Closed_Image" src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingVB.ZipsListDeletingExample.Vb_ListDeletingExample.Vb_DeleteTest_722_66_15_1418_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingVB.ZipsListDeletingExample.Vb_ListDeletingExample.Vb_DeleteTest_722_66_15_1418_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingVB.ZipsListDeletingExample.Vb_ListDeletingExample.Vb_DeleteTest_722_66_15_1418_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_LifecycleDelete_BehaviorListDeletingVB.ZipsListDeletingExample.Vb_ListDeletingExample.Vb_DeleteTest_722_66_15_1418_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub DeleteTest()</span><span id="ResourcesReferenceObject_LifecycleDelete_BehaviorListDeletingVB.ZipsListDeletingExample.Vb_ListDeletingExample.Vb_DeleteTest_722_66_15_1418_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> DeleteTest()
</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: #008000;">'</span><span style="color: #008000;"> set cascadeOnDelete in order to delete member objects</span><span style="color: #008000;">
</span><span style="color: #008080;">03</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">            </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;">04</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;">(ListObject)).CascadeOnDelete(</span><span style="color: #0000FF;">True</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;"> db </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectContainer </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4oFactory.OpenFile(configuration, Db4oFileName)
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Try</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"/>                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> result </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IList(</span><span style="color: #0000FF;">Of</span><span style="color: #000000;"> ListObject) </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Query(</span><span style="color: #0000FF;">Of</span><span style="color: #000000;"> ListObject)(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(ListObject))
</span><span style="color: #008080;">08</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">If</span><span style="color: #000000;"> result.Count </span><span style="color: #000000;">&gt;</span><span style="color: #000000;"> </span><span style="color: #800080;">0</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Then</span><span style="color: #000000;">
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> retrieve a ListObject</span><span style="color: #008000;">
</span><span style="color: #008080;">10</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> lo1 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> ListObject </span><span style="color: #000000;">=</span><span style="color: #000000;"> result(</span><span style="color: #800080;">0</span><span style="color: #000000;">)
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                    </span><span style="color: #008000;">'</span><span style="color: #008000;"> delete the ListObject with all the field objects</span><span style="color: #008000;">
</span><span style="color: #008080;">12</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">                    db.Delete(lo1)
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">If</span><span style="color: #000000;">
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Finally</span><span style="color: #000000;">
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Close()
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Try</span><span style="color: #000000;">
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #008000;">'</span><span style="color: #008000;"> check ListObjects and DataObjects in the database</span><span style="color: #008000;">
</span><span style="color: #008080;">18</span><span style="color: #008000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/></span><span style="color: #000000;">            db </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4oFactory.OpenFile(Db4oFileName)
</span><span style="color: #008080;">19</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Try</span><span style="color: #000000;">
</span><span style="color: #008080;">20</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;"> listObjects </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IList(</span><span style="color: #0000FF;">Of</span><span style="color: #000000;"> ListObject) </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Query(</span><span style="color: #0000FF;">Of</span><span style="color: #000000;"> ListObject)(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(ListObject))
</span><span style="color: #008080;">21</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">ListObjects in the database: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> listObjects.Count.ToString())
</span><span style="color: #008080;">22</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;"> dataObjects </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IList(</span><span style="color: #0000FF;">Of</span><span style="color: #000000;"> DataObject) </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Query(</span><span style="color: #0000FF;">Of</span><span style="color: #000000;"> DataObject)(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(DataObject))
</span><span style="color: #008080;">23</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">DataObjects in the database: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> dataObjects.Count.ToString())
</span><span style="color: #008080;">24</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">Finally</span><span style="color: #000000;">
</span><span style="color: #008080;">25</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Close()
</span><span style="color: #008080;">26</span><span style="color: #000000;"><img src="../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Try</span><span style="color: #000000;">
</span><span style="color: #008080;">27</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>


Please, remember that there is no referential
integrity check on delete: deleted objects might be referenced from elsewhere
in your code.

</div>
    </div>
    <div id="footer">
					This revision (4) was last Modified 2007-05-04T12:56:43 by Tetyana.
				</div>
  </body>
</html>