<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AB-WebLog.com&#187; DevExpress</title>
	<atom:link href="http://www.ab-weblog.com/en/tag/devexpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ab-weblog.com/en</link>
	<description>Andreas Breitschopp</description>
	<lastBuildDate>Wed, 18 Mar 2015 09:47:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>DevExpress XPO: Expensive SQL Query Upon XPCollection.EndInit() Call</title>
		<link>http://www.ab-weblog.com/en/devexpress-xpo-expensive-sql-query-upon-xpcollection-endinit-call/</link>
		<comments>http://www.ab-weblog.com/en/devexpress-xpo-expensive-sql-query-upon-xpcollection-endinit-call/#comments</comments>
		<pubDate>Sat, 10 Nov 2012 11:03:50 +0000</pubDate>
		<dc:creator>Andreas Breitschopp</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[DevExpress]]></category>
		<category><![CDATA[XPO]]></category>

		<guid isPermaLink="false">http://www.ab-weblog.com/en/?p=672</guid>
		<description><![CDATA[For .NET projects I do like to use the controls by DevExpress. Additionally DevExpress XPO is very useful as database abstraction layer. But in a current project I came across a very strange issue: for a few forms (curiously not for &#8230; <a href="http://www.ab-weblog.com/en/devexpress-xpo-expensive-sql-query-upon-xpcollection-endinit-call/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For .NET projects I do like to use the controls by <a title="DevExpress Website" href="http://www.devexpress.com" target="_blank">DevExpress</a>. Additionally DevExpress XPO is very useful as database abstraction layer.</p>
<p>But in a current project I came across a very strange issue:</p>
<p>for a few forms (curiously not for all) a very expensive SQL query is sent to the database backend while the form is loading. It was basically a SQL query that loads all (and I mean really all) data rows from the database which is obviously not a very good idea. But as I wrote that was not the case for all forms: when loading the other forms only the current data object (the current row in the table) was loaded as expected.</p>
<p>Of course, I&#8217;ve first contacted the always very fast and helpful DevExpress support. They researched what causes the data request and determined that the XPCollection.Count property is requested by the CurrencyManager after the Control.UpdateBindings method call. Because that&#8217;s something inside the .NET Framework they can&#8217;t do anything about it unfortunately.</p>
<p>They suggested to not set the XPCollection at design time, but this would result in losing the possibility to build the forms in the Windows Forms Designer. That would have been very bad, because I do have a lot of big forms in this project and I really don&#8217;t like to build them all in code.</p>
<p>But I found another way &#8211; I will not call that solution, just a work-around &#8211; to be still able to use the designer:</p>
<p>Therefore I simple wrote two batch files (using a command line replacement tool called <a title="FART Website" href="http://fart-it.sourceforge.net" target="_blank">FART</a>), one that runs before the build starts and makes sure no XPCollection is initialized in the InitializeComponent method (by just commenting the lines of code) and a second one that runs after the build finished and reverts these changes.</p>
<p>Here is the content of the pre-build batch file:</p>
<pre class="brush: text; gutter: true">%1Tools\fart.exe -r -C &quot;%1*.designer.cs&quot; &quot;this.xpKern = new DevExpress.Xpo.XPCollection(this.components);&quot; &quot;\x2f\x2fthis.xpKern = new DevExpress.Xpo.XPCollection(this.components);&quot;
%1Tools\fart.exe -r -C &quot;%1*.designer.cs&quot; &quot;((System.ComponentModel.ISupportInitialize)(this.xpKern)).BeginInit();&quot; &quot;\x2f\x2f((System.ComponentModel.ISupportInitialize)(this.xpKern)).BeginInit();&quot;
%1Tools\fart.exe -r -C &quot;%1*.designer.cs&quot; &quot;this.xpKern.ObjectType = typeof(Administration.Daten.Kern);&quot; &quot;\x2f\x2fthis.xpKern.ObjectType = typeof(Administration.Daten.Kern);&quot;
%1Tools\fart.exe -r -C &quot;%1*.designer.cs&quot; &quot;this.xpKern.Session = this.unitOfWork;&quot; &quot;\x2f\x2fthis.xpKern.Session = this.unitOfWork;&quot;
%1Tools\fart.exe -r -C &quot;%1*.designer.cs&quot; &quot;((System.ComponentModel.ISupportInitialize)(this.xpKern)).EndInit();&quot; &quot;\x2f\x2f((System.ComponentModel.ISupportInitialize)(this.xpKern)).EndInit();&quot;

@exit 0</pre>
<p>And the post-build one that reverts the changes:</p>
<pre class="brush: text; gutter: true">%1Tools\fart.exe -r -C &quot;%1*.designer.cs&quot; &quot;\x2f\x2fthis.xpKern = new DevExpress.Xpo.XPCollection(this.components);&quot; &quot;this.xpKern = new DevExpress.Xpo.XPCollection(this.components);&quot;
%1Tools\fart.exe -r -C &quot;%1*.designer.cs&quot; &quot;\x2f\x2f((System.ComponentModel.ISupportInitialize)(this.xpKern)).BeginInit();&quot; &quot;((System.ComponentModel.ISupportInitialize)(this.xpKern)).BeginInit();&quot;
%1Tools\fart.exe -r -C &quot;%1*.designer.cs&quot; &quot;\x2f\x2fthis.xpKern.ObjectType = typeof(Administration.Daten.Kern);&quot; &quot;this.xpKern.ObjectType = typeof(Administration.Daten.Kern);&quot;
%1Tools\fart.exe -r -C &quot;%1*.designer.cs&quot; &quot;\x2f\x2fthis.xpKern.Session = this.unitOfWork;&quot; &quot;this.xpKern.Session = this.unitOfWork;&quot;
%1Tools\fart.exe -r -C &quot;%1*.designer.cs&quot; &quot;\x2f\x2f((System.ComponentModel.ISupportInitialize)(this.xpKern)).EndInit();&quot; &quot;((System.ComponentModel.ISupportInitialize)(this.xpKern)).EndInit();&quot;

@exit 0</pre>
<p>The <code class="brush: text; gutter: false">@exit 0</code> at the end of them is important as otherwise code 2 is returned (for whatever reason) and the Visual Studio build system will complain about it every build.</p>
<p>Now you just need to call these batch files in the Visual Studio build events with</p>
<pre class="brush: text; gutter: false">$(ProjectDir)Tools\PreBuild.bat $(ProjectDir)</pre>
<p>respectively:</p>
<pre class="brush: text; gutter: false">$(ProjectDir)Tools\PostBuild.bat $(ProjectDir)</pre>
<p>I know that this is not a very good &#8220;solution&#8221;, but the only idea I had that I can still use the form designer while avoiding these expensive SQL queries.</p>
<p><em>Did you ever have the same issue and maybe even a better solution for it? I&#8217;m looking forward to any other suggestion on this topic!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ab-weblog.com/en/devexpress-xpo-expensive-sql-query-upon-xpcollection-endinit-call/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->