Sophie

Sophie

distrib > Fedora > 14 > i386 > by-pkgid > 864d1c3c3cd8df4e3a2692faf8776e05 > files > 932

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

<html>
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Snapshot Queries</title>
    <link rel="stylesheet" type="text/css" href="../../../../style.css">
  </head>
  <body>
    <div class="CommonContent">
      <div class="CommonContentArea">
        <h1>Snapshot Queries</h1><div id="TOC"><div id="TOCinner"><span class="TOCtitle">Contents</span><div class="TOCcontents"><ul><li><a href ="#Pros and Cons for Snapshot Queries">Pros and Cons for Snapshot Queries</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>Snapshot mode allows you to get the advantages of the Lazy queries avoiding their side effects. When query is executed, the query processor chooses the best indexes, does all index processing and creates a snapshot of the index at this point in time. Non-indexed constraints are evaluated lazily when the application iterates through the <CODE>ObjectSet</CODE> resultset of the query.</P>

<span name="cs_wiki_filter" csw_filters="cs">
<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">QueryModesExample.cs: <span class="fscMemberName">TestSnapshotQueries</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70"><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;"> TestSnapshotQueries()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_50_974_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_50_974_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_50_974_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_50_974_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_50_974_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_50_974_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_50_974_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_50_974_Open_Text').style.display='inline';"/>        </span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_50_974_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_50_974_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"/>            Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Testing query performance on 10000 pilot objects in Snapshot mode</span><span style="color: #800000;">&quot;</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"/>            FillUpDB(</span><span style="color: #800080;">10000</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"/>            IConfiguration configuration </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4oFactory.NewConfiguration();
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            configuration.Queries().EvaluationMode(QueryEvaluationMode.SNAPSHOT);
</span><span style="color: #008080;">07</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;">08</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;">09</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_451_888_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_451_888_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_451_888_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_451_888_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_451_888_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_451_888_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_451_888_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_451_888_Open_Text').style.display='inline';"/>            </span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_451_888_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_451_888_Open_Text"><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"/>                IQuery query </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Query();
</span><span style="color: #008080;">11</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;">(Pilot));
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                query.Descend(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">_points</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">).Constrain(</span><span style="color: #800080;">99</span><span style="color: #000000;">).Greater();
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                DateTime dt1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> DateTime.UtcNow;
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                query.Execute();
</span><span style="color: #008080;">15</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                DateTime dt2 </span><span style="color: #000000;">=</span><span style="color: #000000;"> DateTime.UtcNow;
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                TimeSpan diff </span><span style="color: #000000;">=</span><span style="color: #000000;"> dt2 </span><span style="color: #000000;">-</span><span style="color: #000000;"> dt1;
</span><span style="color: #008080;">17</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;">Query execution time=</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> diff.TotalMilliseconds </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;"> ms</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">);
</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: #0000FF;">finally</span><span style="color: #000000;">
</span><span style="color: #008080;">20</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_921_964_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_921_964_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_921_964_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_921_964_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_921_964_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_921_964_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_921_964_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_921_964_Open_Text').style.display='inline';"/>            </span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_921_964_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotQueries_447_70_921_964_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">21</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Close();
</span><span style="color: #008080;">22</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;">23</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">QueryModesExample.vb: <span class="fscMemberName">TestSnapshotQueries</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotQueries_575_70"><div><!--

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

--><span style="color: #008080;">01</span><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotQueries_575_70_15_969_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotQueries_575_70_15_969_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotQueries_575_70_15_969_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotQueries_575_70_15_969_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotQueries_575_70_15_969_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotQueries_575_70_15_969_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotQueries_575_70_15_969_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotQueries_575_70_15_969_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_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotQueries_575_70_15_969_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub TestSnapshotQueries()</span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotQueries_575_70_15_969_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> TestSnapshotQueries()
</span><span style="color: #008080;">02</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;">Testing query performance on 10000 pilot objects in Snapshot mode</span><span style="color: #800000;">&quot;</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"/>            FillUpDB(</span><span style="color: #800080;">10000</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"/>            </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;">05</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            configuration.Queries.EvaluationMode(QueryEvaluationMode.SNAPSHOT)
</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;"> 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;">07</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;">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;"> query </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IQuery </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.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;">GetType</span><span style="color: #000000;">(Pilot))
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                query.Descend(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">_points</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">).Constrain(</span><span style="color: #800080;">99</span><span style="color: #000000;">).Greater()
</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;">Dim</span><span style="color: #000000;"> dt1 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> DateTime </span><span style="color: #000000;">=</span><span style="color: #000000;"> DateTime.UtcNow
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                query.Execute()
</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;">Dim</span><span style="color: #000000;"> dt2 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> DateTime </span><span style="color: #000000;">=</span><span style="color: #000000;"> DateTime.UtcNow
</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;">Dim</span><span style="color: #000000;"> diff </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> TimeSpan </span><span style="color: #000000;">=</span><span style="color: #000000;"> dt2 </span><span style="color: #000000;">-</span><span style="color: #000000;"> dt1
</span><span style="color: #008080;">15</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;">Query execution time=</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> diff.TotalMilliseconds.ToString() </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;"> ms</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">)
</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;">Finally</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"/>                db.Close()
</span><span style="color: #008080;">18</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;">19</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>Snapshot queries ensure better performance than Immediate queries, but the performance will depend on the size of the resultset.</P>
<P>As the snapshot of the results is kept in memory the result set is not affected by the changes from the caller or from another transaction (compare the results of this code snippet to the one from <a href="lazy_queries.html" class="wikiLink">Lazy Queries</a> topic):</P>

<span name="cs_wiki_filter" csw_filters="cs">
<div class="FormattedSourceCode"><div class="fscHeader"><span class="fscFileName">QueryModesExample.cs: <span class="fscMemberName">TestSnapshotConcurrent</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73"><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;"> TestSnapshotConcurrent()
</span><span style="color: #008080;">02</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_53_1413_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_53_1413_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_53_1413_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_53_1413_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_53_1413_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_53_1413_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_53_1413_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_53_1413_Open_Text').style.display='inline';"/>        </span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_53_1413_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_53_1413_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"/>            Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Testing snapshot mode with concurrent modifications</span><span style="color: #800000;">&quot;</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"/>            FillUpDB(</span><span style="color: #800080;">10</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"/>            IConfiguration configuration </span><span style="color: #000000;">=</span><span style="color: #000000;"> Db4oFactory.NewConfiguration();
</span><span style="color: #008080;">06</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            configuration.Queries().EvaluationMode(QueryEvaluationMode.SNAPSHOT);
</span><span style="color: #008080;">07</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;">08</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;">09</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_437_1327_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_437_1327_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_437_1327_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_437_1327_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_437_1327_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_437_1327_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_437_1327_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_437_1327_Open_Text').style.display='inline';"/>            </span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_437_1327_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_437_1327_Open_Text"><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"/>                IQuery query1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Query();
</span><span style="color: #008080;">11</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                query1.Constrain(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Pilot));
</span><span style="color: #008080;">12</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                query1.Descend(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">_points</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">).Constrain(</span><span style="color: #800080;">5</span><span style="color: #000000;">).Smaller();
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                IObjectSet result1 </span><span style="color: #000000;">=</span><span style="color: #000000;"> query1.Execute();
</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: #008080;">15</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                IQuery query2 </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Query();
</span><span style="color: #008080;">16</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                query2.Constrain(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(Pilot));
</span><span style="color: #008080;">17</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                query2.Descend(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">_points</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">).Constrain(</span><span style="color: #800080;">1</span><span style="color: #000000;">);
</span><span style="color: #008080;">18</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                IObjectSet result2 </span><span style="color: #000000;">=</span><span style="color: #000000;"> query2.Execute();
</span><span style="color: #008080;">19</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                Pilot pilotToDelete </span><span style="color: #000000;">=</span><span style="color: #000000;"> (Pilot)result2[</span><span style="color: #800080;">0</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"/>                Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Pilot to be deleted: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilotToDelete);
</span><span style="color: #008080;">21</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Delete(pilotToDelete);
</span><span style="color: #008080;">22</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;">&quot;</span><span style="color: #800000;">Tester</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">, </span><span style="color: #800080;">2</span><span style="color: #000000;">);
</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;">Pilot to be added: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilot);
</span><span style="color: #008080;">24</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Set(pilot);
</span><span style="color: #008080;">25</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>
</span><span style="color: #008080;">26</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;">Query result after changing from the same transaction</span><span style="color: #800000;">&quot;</span><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"/>                ListResult(result1);
</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/InBlock.gif" align="top"/>            </span><span style="color: #0000FF;">finally</span><span style="color: #000000;">
</span><span style="color: #008080;">30</span><span style="color: #000000;"><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_1360_1403_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_1360_1403_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_1360_1403_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_1360_1403_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_1360_1403_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedSubBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_1360_1403_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_1360_1403_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_1360_1403_Open_Text').style.display='inline';"/>            </span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_1360_1403_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">...</span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeCS.ZipsQueryModesExample.Cs_QueryModesExample.Cs_TestSnapshotConcurrent_1085_73_1360_1403_Open_Text"><span style="color: #000000;">{
</span><span style="color: #008080;">31</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Close();
</span><span style="color: #008080;">32</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;">33</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">QueryModesExample.vb: <span class="fscMemberName">TestSnapshotConcurrent</span></span></div><div class="fscCode"><pre ID="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotConcurrent_1216_73"><div><!--

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

--><span style="color: #008080;">01</span><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotConcurrent_1216_73_15_1425_Open_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ExpandedBlockStart.gif" align="top" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotConcurrent_1216_73_15_1425_Open_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotConcurrent_1216_73_15_1425_Closed_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotConcurrent_1216_73_15_1425_Closed_Text').style.display='inline';"/><img id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotConcurrent_1216_73_15_1425_Closed_Image" src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/ContractedBlock.gif" align="top" style="display: none;" onClick="this.style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotConcurrent_1216_73_15_1425_Closed_Text').style.display='none'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotConcurrent_1216_73_15_1425_Open_Image').style.display='inline'; document.getElementById('ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotConcurrent_1216_73_15_1425_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_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotConcurrent_1216_73_15_1425_Closed_Text" style="border: solid 1px #808080; background-color: #FFFFFF; display: none;">Sub TestSnapshotConcurrent()</span><span id="ResourcesReferenceObject_LifecycleQueryingQuery_ModesquerymodeVB.ZipsQueryModesExample.Vb_QueryModesExample.Vb_TestSnapshotConcurrent_1216_73_15_1425_Open_Text"><span style="color: #0000FF;">Sub</span><span style="color: #000000;"> TestSnapshotConcurrent()
</span><span style="color: #008080;">02</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;">Testing snapshot mode with concurrent modifications</span><span style="color: #800000;">&quot;</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"/>            FillUpDB(</span><span style="color: #800080;">10</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"/>            </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;">05</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>            configuration.Queries.EvaluationMode(QueryEvaluationMode.SNAPSHOT)
</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;"> 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;">07</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;">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;"> query1 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IQuery </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Query
</span><span style="color: #008080;">09</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                query1.Constrain(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(Pilot))
</span><span style="color: #008080;">10</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                query1.Descend(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">_points</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">).Constrain(</span><span style="color: #800080;">5</span><span style="color: #000000;">).Smaller()
</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;">Dim</span><span style="color: #000000;"> result1 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> query1.Execute
</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;">Dim</span><span style="color: #000000;"> query2 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IQuery </span><span style="color: #000000;">=</span><span style="color: #000000;"> db.Query
</span><span style="color: #008080;">13</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                query2.Constrain(</span><span style="color: #0000FF;">GetType</span><span style="color: #000000;">(Pilot))
</span><span style="color: #008080;">14</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                query2.Descend(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">_points</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">).Constrain(</span><span style="color: #800080;">1</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"/>                </span><span style="color: #0000FF;">Dim</span><span style="color: #000000;"> result2 </span><span style="color: #0000FF;">As</span><span style="color: #000000;"> IObjectSet </span><span style="color: #000000;">=</span><span style="color: #000000;"> query2.Execute
</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;">Dim</span><span style="color: #000000;"> pilotToDelete </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;">CType</span><span style="color: #000000;">(result2(</span><span style="color: #800080;">0</span><span style="color: #000000;">), Pilot)
</span><span style="color: #008080;">17</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;">Pilot to be deleted: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilotToDelete.ToString())
</span><span style="color: #008080;">18</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Delete(pilotToDelete)
</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;">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;">&quot;</span><span style="color: #800000;">Tester</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">, </span><span style="color: #800080;">2</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"/>                Console.WriteLine(</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">Pilot to be added: </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> pilot.ToString())
</span><span style="color: #008080;">21</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                db.Set(pilot)
</span><span style="color: #008080;">22</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;">Query result after changing from the same transaction</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">)
</span><span style="color: #008080;">23</span><span style="color: #000000;"><img src="../../../../Utility/ActiPro.CodeHighligher/OutliningIndicators/InBlock.gif" align="top"/>                ListResult(result1)
</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>
<a name="Pros and Cons for Snapshot Queries"></a><H2>Pros and Cons for Snapshot Queries</H2>
<P>Pros:</P>
<UL>
<LI>Index processing will happen without possible side effects from changes made by the caller or by other transaction.</LI>
<LI>Since index processing is fast, a server will not be blocked for a long time.</LI></UL>
<P>Cons:</P>
<UL>
<LI>The entire candidate index will be loaded into memory. It will stay there until the query ObjectSet is garbage collected. In a C/S setup, the memory will be used on the server side</LI></UL>
<P>Client/Server applications with the risk of concurrent modifications should prefer Snapshot mode to avoid side effects from other transactions.</P></div>
    </div>
    <div id="footer">
					This revision (6) was last Modified 2007-11-21T17:34:25 by Eric Falsken.
				</div>
  </body>
</html>