<html> <head> <META http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Class Mapping</title> <link rel="stylesheet" type="text/css" href="../../style.css"> </head> <body> <div class="CommonContent"> <div class="CommonContentArea"> <h1>Class Mapping</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>[This functionality is deprecated] </p><p>db4o provides you with a possibility to create a mapping from a class in the database to a runtime class. </p> <span name="cs_wiki_filter" csw_filters="cs"><p>c#: </p> <p><code>IObjectClass.ReadAs(object clazz)</code></p> </span> <span name="cs_wiki_filter" csw_filters="vb"><p>VB: </p> <p><code>IObjectClass.ReadAs(Type clazz)</code></p> </span> <p><code>clazz</code> parameter specifies a runtime class, which will be used to instantiate objects from the database.</p> <p>The use-case is the following:</p> <ul><li>objects of class A are stored to the database;</li><li>the objects should be retrieved from the database and instantiated as objects of class B.</li></ul> <span name="cs_wiki_filter" csw_filters="cs"><p>c#: </p> <p><code>Db4oFactory.Configure().ObjectClass(typeof(A)).readAs(typeof(B)) </code></p> </span> <span name="cs_wiki_filter" csw_filters="vb"><p>VB: </p> <p><code>IObjectClass.ReadAs(Type clazz)</code></p> </span> <p>This configuration should be set before opening a database file.</p> <p>The mapping functionality is similar to <a href="aliases.html" class="wikiLink">Aliases</a>, but more limited.</p> <p>Let's look at an example.</p> <p>We will use 2 identical classes <a href="class_mapping/pilot.html" class="wikiLink">Pilot</a> and <a href="class_mapping/pilotreplacement.html" class="wikiLink">PilotReplacement</a>.</p> <p>Objects of Pilot class will be saved to the database:</p> <span name="cs_wiki_filter" csw_filters="cs"> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">MappingExample.cs: <span class="fscMemberName">StoreObjects</span></span></div><div class="fscCode"><pre ID=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65"><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;"> StoreObjects() </span><span style="color: #008080;">02</span><span style="color: #000000;"><img id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_43_501_Open_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_43_501_Open_Text').style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_43_501_Closed_Image').style.display='inline'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_43_501_Closed_Text').style.display='inline';"/><img id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_43_501_Closed_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_43_501_Closed_Text').style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_43_501_Open_Image').style.display='inline'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_43_501_Open_Text').style.display='inline';"/> </span><span id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_43_501_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_43_501_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"/> File.Delete(Db4oFileName); </span><span style="color: #008080;">04</span><span style="color: #000000;"><img src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> IObjectContainer container </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4oFactory.OpenFile(Db4oFileName); </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;">try</span><span style="color: #000000;"> </span><span style="color: #008080;">06</span><span style="color: #000000;"><img id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_189_408_Open_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_189_408_Open_Text').style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_189_408_Closed_Image').style.display='inline'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_189_408_Closed_Text').style.display='inline';"/><img id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_189_408_Closed_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_189_408_Closed_Text').style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_189_408_Open_Image').style.display='inline'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_189_408_Open_Text').style.display='inline';"/> </span><span id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_189_408_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_189_408_Open_Text"><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"/> Pilot 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: #800000;">"</span><span style="color: #800000;">Michael Schumacher</span><span style="color: #800000;">"</span><span style="color: #000000;">, </span><span style="color: #800080;">100</span><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"/> container.Set(pilot); </span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> 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: #800000;">"</span><span style="color: #800000;">Rubens Barichello</span><span style="color: #800000;">"</span><span style="color: #000000;">, </span><span style="color: #800080;">99</span><span style="color: #000000;">); </span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> container.Set(pilot); </span><span style="color: #008080;">11</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;">12</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;">13</span><span style="color: #000000;"><img id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_441_491_Open_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_441_491_Open_Text').style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_441_491_Closed_Image').style.display='inline'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_441_491_Closed_Text').style.display='inline';"/><img id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_441_491_Closed_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_441_491_Closed_Text').style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_441_491_Open_Image').style.display='inline'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_441_491_Open_Text').style.display='inline';"/> </span><span id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_441_491_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_StoreObjects_1479_65_441_491_Open_Text"><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"/> container.Close(); </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 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">MappingExample.vb: <span class="fscMemberName">StoreObjects</span></span></div><div class="fscCode"><pre ID=".ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_StoreObjects_1608_65"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">01</span><img id=".ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_StoreObjects_1608_65_15_467_Open_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('.ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_StoreObjects_1608_65_15_467_Open_Text').style.display='none'; document.getElementById('.ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_StoreObjects_1608_65_15_467_Closed_Image').style.display='inline'; document.getElementById('.ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_StoreObjects_1608_65_15_467_Closed_Text').style.display='inline';"/><img id=".ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_StoreObjects_1608_65_15_467_Closed_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('.ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_StoreObjects_1608_65_15_467_Closed_Text').style.display='none'; document.getElementById('.ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_StoreObjects_1608_65_15_467_Open_Image').style.display='inline'; document.getElementById('.ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_StoreObjects_1608_65_15_467_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=".ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_StoreObjects_1608_65_15_467_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub StoreObjects()</span><span id=".ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_StoreObjects_1608_65_15_467_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> StoreObjects() </span><span style="color: #008080;">02</span><span style="color: #000000;"><img src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> File.Delete(Db4oFileName) </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;"> container </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectContainer </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4oFactory.OpenFile(Db4oFileName) </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;">Try</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;"> 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;">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;">100</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"/> container.Set(pilot) </span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> 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: #800000;">"</span><span style="color: #800000;">Rubens Barichello</span><span style="color: #800000;">"</span><span style="color: #000000;">, </span><span style="color: #800080;">99</span><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"/> container.Set(pilot) </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;">Finally</span><span style="color: #000000;"> </span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> container.Close() </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: #0000FF;">End</span><span style="color: #000000;"> </span><span style="color: #0000FF;">Try</span><span style="color: #000000;"> </span><span style="color: #008080;">12</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>Let's try to retrieve the persisted objects using PilotReplacement class:</p> <span name="cs_wiki_filter" csw_filters="cs"> <div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">MappingExample.cs: <span class="fscMemberName">RetrieveObjects</span></span></div><div class="fscCode"><pre ID=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68"><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;"> RetrieveObjects() </span><span style="color: #008080;">02</span><span style="color: #000000;"><img id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_46_636_Open_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_46_636_Open_Text').style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_46_636_Closed_Image').style.display='inline'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_46_636_Closed_Text').style.display='inline';"/><img id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_46_636_Closed_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_46_636_Closed_Text').style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_46_636_Open_Image').style.display='inline'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_46_636_Open_Text').style.display='inline';"/> </span><span id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_46_636_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_46_636_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"/> 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;">(Pilot)).ReadAs(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(PilotReplacement)); </span><span style="color: #008080;">05</span><span style="color: #000000;"><img src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> IObjectContainer container </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=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_330_543_Open_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_330_543_Open_Text').style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_330_543_Closed_Image').style.display='inline'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_330_543_Closed_Text').style.display='inline';"/><img id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_330_543_Closed_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_330_543_Closed_Text').style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_330_543_Open_Image').style.display='inline'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_330_543_Open_Text').style.display='inline';"/> </span><span id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_330_543_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_330_543_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"/> IQuery query </span><span style="color: #000000;">=</span><span style="color: #000000;"> container.Query(); </span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> query.Constrain(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(PilotReplacement)); </span><span style="color: #008080;">10</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;"> query.Execute(); </span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> ListResult(result); </span><span style="color: #008080;">12</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;">13</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;">14</span><span style="color: #000000;"><img id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_576_626_Open_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_576_626_Open_Text').style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_576_626_Closed_Image').style.display='inline'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_576_626_Closed_Text').style.display='inline';"/><img id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_576_626_Closed_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_576_626_Closed_Text').style.display='none'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_576_626_Open_Image').style.display='inline'; document.getElementById('.ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_576_626_Open_Text').style.display='inline';"/> </span><span id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_576_626_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id=".ClassMappingCS.ZipsMappingExample.Cs_MappingExample.Cs_RetrieveObjects_1826_68_576_626_Open_Text"><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"/> container.Close(); </span><span style="color: #008080;">16</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;">17</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">MappingExample.vb: <span class="fscMemberName">RetrieveObjects</span></span></div><div class="fscCode"><pre ID=".ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_RetrieveObjects_1958_68"><div><!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --><span style="color: #008080;">01</span><img id=".ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_RetrieveObjects_1958_68_15_581_Open_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('.ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_RetrieveObjects_1958_68_15_581_Open_Text').style.display='none'; document.getElementById('.ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_RetrieveObjects_1958_68_15_581_Closed_Image').style.display='inline'; document.getElementById('.ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_RetrieveObjects_1958_68_15_581_Closed_Text').style.display='inline';"/><img id=".ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_RetrieveObjects_1958_68_15_581_Closed_Image" src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('.ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_RetrieveObjects_1958_68_15_581_Closed_Text').style.display='none'; document.getElementById('.ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_RetrieveObjects_1958_68_15_581_Open_Image').style.display='inline'; document.getElementById('.ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_RetrieveObjects_1958_68_15_581_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=".ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_RetrieveObjects_1958_68_15_581_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub RetrieveObjects()</span><span id=".ClassMappingVB.ZipsMappingExample.Vb_MappingExample.Vb_RetrieveObjects_1958_68_15_581_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> RetrieveObjects() </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;"> configuration </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IConfiguration </span><span style="color: #008080;">03</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;">(Pilot)).ReadAs(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(PilotReplacement)) </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;"> container </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;">05</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;">06</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;"> query </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IQuery </span><span style="color: #000000;">=</span><span style="color: #000000;"> container.Query </span><span style="color: #008080;">07</span><span style="color: #000000;"><img src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> query.Constrain(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(PilotReplacement)) </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;">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;"> query.Execute </span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> ListResult(result) </span><span style="color: #008080;">10</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;">11</span><span style="color: #000000;"><img src="../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/> container.Close() </span><span style="color: #008080;">12</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;">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> <p>If meta information for this mapping class has been stored before to the database file, <code>readAs</code> method will have no effect.</p> </div> </div> <div id="footer"> This revision (5) was last Modified 2007-05-07T12:36:22 by Tetyana. </div> </body> </html>