<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Svetlin Ralchev&#039;s Blog</title>
	<atom:link href="http://blog.ralch.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ralch.com</link>
	<description>Software Developer Adventures</description>
	<lastBuildDate>Thu, 03 Mar 2011 15:51:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.ralch.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Svetlin Ralchev&#039;s Blog</title>
		<link>http://blog.ralch.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.ralch.com/osd.xml" title="Svetlin Ralchev&#039;s Blog" />
	<atom:link rel='hub' href='http://blog.ralch.com/?pushpress=hub'/>
		<item>
		<title>How to use Mono in Visual Studio 2010</title>
		<link>http://blog.ralch.com/2011/02/13/how-to-use-mono-on-visual-studio-2010/</link>
		<comments>http://blog.ralch.com/2011/02/13/how-to-use-mono-on-visual-studio-2010/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 09:35:09 +0000</pubDate>
		<dc:creator>Svetlin Ralchev</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">https://ralch.wordpress.com/?p=350</guid>
		<description><![CDATA[The latest version of Visual Studio allows us to use different target framework of the project that we are developing. This give us the opportunity to use the Mono Framework via Visual Studio. Hence, we can target the Linux platform without leaving the Visual Studio Environment. What do you need? Mono for Windows, Gtk#, and <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=350&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The latest version of Visual Studio allows us to use different target framework of the project that we are developing. This give us the opportunity to use the Mono Framework via Visual Studio. Hence, we can target the Linux platform without leaving the Visual Studio Environment.</p>
<h4>What do you need?</h4>
<ul>
<li><a href="http://ftp.novell.com/pub/mono/archive/2.8.2/windows-installer/1/mono-2.8.2-gtksharp-2.12.10-win32-1.exe" target="_blank">Mono for Windows, Gtk#, and XSP</a></li>
</ul>
<p>After the step by step installation, you should go to the library folder which usually is located here: <strong><em>C:\Program Files\Mono-2.8.2\lib\mono\4.0</em></strong></p>
<p>Then you should copy all assemblies to</p>
<p><strong><em>C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Mono</em></strong></p>
<p>After that you should create the <strong>RedistList</strong> folder under the <strong>Mono</strong> folder. Then you can create <strong>FrameworkList.xml</strong> file with the following content:</p>
<pre class="code"><span style="color:blue;">&lt;?</span><span style="color:#a31515;">xml </span><span style="color:red;">version</span><span style="color:blue;">=</span>"<span style="color:blue;">1.0</span>" <span style="color:red;">encoding</span><span style="color:blue;">=</span>"<span style="color:blue;">utf-8</span>"<span style="color:blue;">?&gt;
&lt;</span><span style="color:#a31515;">FileList  </span><span style="color:red;">Redist</span><span style="color:blue;">=</span>"<span style="color:blue;">Mono_2.8.2</span>" <span style="color:red;">Name</span><span style="color:blue;">=</span>"<span style="color:blue;">Mono 2.8.2 Profile</span>" <span style="color:red;">RuntimeVersion</span><span style="color:blue;">=</span>"<span style="color:blue;">2.0</span>" <span style="color:red;">ToolsVersion</span><span style="color:blue;">=</span>"<span style="color:blue;">2.0</span>"<span style="color:blue;">&gt;
&lt;/</span><span style="color:#a31515;">FileList</span><span style="color:blue;">&gt;
</span></pre>
<p>Now you should start the Visual Studio 2010 and change the target framework of your project via the properties panel:</p>
<p><a href="http://ralch.files.wordpress.com/2011/02/mono_framework.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;margin:0 0 10px;" title="mono_framework" src="http://ralch.files.wordpress.com/2011/02/mono_framework_thumb.jpg?w=500&#038;h=365" border="0" alt="mono_framework" width="500" height="365" /></a></p>
<h4>Linux compatibility</h4>
<p>If you want to check for the project compatibility with the Linux platform, you should download the <strong>Mono Migration Analyzer</strong> tool (<strong>MoMa</strong>) from <a href="http://www.go-mono.com/archive/moma/Moma2-8.zip" target="_blank">here</a>.</p>
<p>You can integrate it in your project build in this way:</p>
<p><a href="http://ralch.files.wordpress.com/2011/02/mona.jpg"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;margin:0 0 10px;" title="mona" src="http://ralch.files.wordpress.com/2011/02/mona_thumb.jpg?w=500&#038;h=384" border="0" alt="mona" width="500" height="384" /></a></p>
<p>Notice that you should add the installation folder of <strong>MoMa</strong> to the system environment variable <strong><em>PATH.</em></strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ralch.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ralch.wordpress.com/350/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ralch.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ralch.wordpress.com/350/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ralch.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ralch.wordpress.com/350/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ralch.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ralch.wordpress.com/350/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ralch.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ralch.wordpress.com/350/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ralch.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ralch.wordpress.com/350/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ralch.wordpress.com/350/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ralch.wordpress.com/350/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=350&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ralch.com/2011/02/13/how-to-use-mono-on-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fc622ca8108ba3e8faaa40486ebfb53?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ralch</media:title>
		</media:content>

		<media:content url="http://ralch.files.wordpress.com/2011/02/mono_framework_thumb.jpg" medium="image">
			<media:title type="html">mono_framework</media:title>
		</media:content>

		<media:content url="http://ralch.files.wordpress.com/2011/02/mona_thumb.jpg" medium="image">
			<media:title type="html">mona</media:title>
		</media:content>
	</item>
		<item>
		<title>Fast run-time emitting with Dynamic Methods</title>
		<link>http://blog.ralch.com/2011/02/06/fast-methods-emitting-with-dynamic-methods/</link>
		<comments>http://blog.ralch.com/2011/02/06/fast-methods-emitting-with-dynamic-methods/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 09:09:00 +0000</pubDate>
		<dc:creator>Svetlin Ralchev</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Dynamic Methods]]></category>
		<category><![CDATA[Reflection]]></category>

		<guid isPermaLink="false">https://ralch.wordpress.com/?p=326</guid>
		<description><![CDATA[It was a long time since, I have blogged. Nevertheless, I did not loose the enthusiasm to share the interesting stuff that I face. As component software developer, you should know how to access the properties of data source, when you create bound able controls (such as list control, combo box control or even grid <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=326&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It was a long time since, I have blogged. Nevertheless, I did not loose the enthusiasm to share the interesting stuff that I face. As component software developer, you should know how to access the properties of data source, when you create bound able controls (such as list control, combo box control or even grid control). The performance has always been a issue due to the fact that the control should work with any type of data source (ex. DataSet, DataTable or Entity Objects). Such requirements cause the developer to use reflection to access all properties of unknown object type. Therefore, you should use the <strong>PropertyInfo</strong> or <strong>PropertyDescriptor</strong>&#160; classes. The disadvantage of the reflection has been always the performance. We should always care about that. However, there is good alterative that can give satisfactory speed and unlimited power of the reflection. The <strong>Dynamic Methods</strong> provide lightweight code generation and execution of method at run-time via delegates.</p>
<p>(<a href="http://msdn.microsoft.com/en-us/library/sfk2s47t.aspx" target="_blank">MSDN</a>)<strong> Dynamic methods</strong> expand the functionality of the types in the System.Reflection.Emit namespace in several ways:</p>
<ul>
<li>They have less overhead, because there is no need to generate dynamic assemblies, modules, and types to contain the methods. </li>
<li>In long-running applications, they provide better resource utilization because the memory used by method bodies can be reclaimed when the method is no longer needed. </li>
<li>Given sufficient security permissions, they provide the ability to associate code with an existing assembly or type, and that code can have the same visibility as internal types or private members. </li>
<li>Given sufficient security permissions, they allow code to skip just-in-time (JIT) visibility checks and access the private and protected data of objects.      </li>
</ul>
<p>Before you define the method body, you should declare the delegate types that you should use to access the properties of the unknown type:</p>
<pre class="code"><span style="color:blue;">protected delegate void </span><span style="color:#2b91af;">SetValueHandler</span>(<span style="color:blue;">object </span>component, <span style="color:blue;">object </span>value);
<span style="color:blue;">protected delegate object </span><span style="color:#2b91af;">GetValueHandler</span>(<span style="color:blue;">object </span>component);</pre>
<p>To define the methods’ bodies you should feel comfortable with Microsoft Intermediate Language (IL). </p>
<p>By using the <strong>ILGenerator</strong> class, you can define the getter method in this way:</p>
<pre class="code"><span style="color:blue;">protected virtual </span><span style="color:#2b91af;">GetValueHandler </span>CreateGetValueHandler(<span style="color:#2b91af;">PropertyInfo </span>propertyInfo)
{
    <span style="color:#2b91af;">MethodInfo </span>getMethodInfo = propertyInfo.GetGetMethod();
    <span style="color:#2b91af;">DynamicMethod </span>getMethod = <span style="color:blue;">new </span><span style="color:#2b91af;">DynamicMethod</span>(<span style="color:#a31515;">&quot;GetValue&quot;</span>, <span style="color:blue;">typeof</span>(<span style="color:blue;">object</span>), <span style="color:blue;">new </span><span style="color:#2b91af;">Type</span>[] { <span style="color:blue;">typeof</span>(<span style="color:blue;">object</span>) }, <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">PropertyAccessor</span>), <span style="color:blue;">true</span>);
    <span style="color:#2b91af;">ILGenerator </span>ilGenerator = getMethod.GetILGenerator();

    ilGenerator.Emit(<span style="color:#2b91af;">OpCodes</span>.Ldarg_0);
    ilGenerator.Emit(<span style="color:#2b91af;">OpCodes</span>.Call, getMethodInfo);

    <span style="color:#2b91af;">Type </span>returnType = getMethodInfo.ReturnType;

    <span style="color:blue;">if </span>(returnType.IsValueType)
    {
        ilGenerator.Emit(<span style="color:#2b91af;">OpCodes</span>.Box, returnType);
    }

    ilGenerator.Emit(<span style="color:#2b91af;">OpCodes</span>.Ret);

    <span style="color:blue;">return </span>getMethod.CreateDelegate(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">GetValueHandler</span>)) <span style="color:blue;">as </span><span style="color:#2b91af;">GetValueHandler</span>;

}</pre>
<p>Also, the body of the setter method should be created as it’s shown in the following code snippet:</p>
<pre class="code"><span style="color:blue;">protected virtual </span><span style="color:#2b91af;">SetValueHandler </span>CreateSetValueHandler(<span style="color:#2b91af;">PropertyInfo </span>propertyInfo)
{
    <span style="color:#2b91af;">MethodInfo </span>setMethodInfo = propertyInfo.GetSetMethod(<span style="color:blue;">false</span>);
    <span style="color:#2b91af;">DynamicMethod </span>setPropertyValue = <span style="color:blue;">new </span><span style="color:#2b91af;">DynamicMethod</span>(<span style="color:#a31515;">&quot;SetValue&quot;</span>, <span style="color:blue;">typeof</span>(<span style="color:blue;">void</span>), <span style="color:blue;">new </span><span style="color:#2b91af;">Type</span>[] { <span style="color:blue;">typeof</span>(<span style="color:blue;">object</span>), <span style="color:blue;">typeof</span>(<span style="color:blue;">object</span>) }, <span style="color:blue;">typeof</span>(<span style="color:#2b91af;">PropertyAccessor</span>), <span style="color:blue;">true</span>);
    <span style="color:#2b91af;">ILGenerator </span>ilGenerator = setPropertyValue.GetILGenerator();

    ilGenerator.Emit(<span style="color:#2b91af;">OpCodes</span>.Ldarg_0);
    ilGenerator.Emit(<span style="color:#2b91af;">OpCodes</span>.Ldarg_1);

    <span style="color:#2b91af;">Type </span>parameterType = setMethodInfo.GetParameters()[0].ParameterType;

    <span style="color:blue;">if </span>(parameterType.IsValueType)
    {
        ilGenerator.Emit(<span style="color:#2b91af;">OpCodes</span>.Unbox_Any, parameterType);
    }

    ilGenerator.Emit(<span style="color:#2b91af;">OpCodes</span>.Call, setMethodInfo);
    ilGenerator.Emit(<span style="color:#2b91af;">OpCodes</span>.Ret);

    <span style="color:blue;">return </span>setPropertyValue.CreateDelegate(<span style="color:blue;">typeof</span>(<span style="color:#2b91af;">SetValueHandler</span>)) <span style="color:blue;">as </span><span style="color:#2b91af;">SetValueHandler</span>;
}</pre>
<p>I have encapsulated the dynamic method accesses in the <strong>PropertyAccessor</strong> class, which declaration looks as follows:</p>
<pre class="code"><span style="color:blue;">public class </span><span style="color:#2b91af;">PropertyAccessor
</span>{
    <span style="color:blue;">protected delegate void </span><span style="color:#2b91af;">SetValueHandler</span>(<span style="color:blue;">object </span>component, <span style="color:blue;">object </span>value);
    <span style="color:blue;">protected delegate object </span><span style="color:#2b91af;">GetValueHandler</span>(<span style="color:blue;">object </span>component);

    <span style="color:blue;">private </span><span style="color:#2b91af;">SetValueHandler </span>setValueHandler;
    <span style="color:blue;">private </span><span style="color:#2b91af;">GetValueHandler </span>getValueHandler;

    <span style="color:blue;">public </span>PropertyAccessor(<span style="color:#2b91af;">Type </span>ownerType, <span style="color:blue;">string </span>propertyName)
        {
            <span style="color:#2b91af;">PropertyInfo </span>propertyInfo = ownerType.GetProperty(propertyName);

            <span style="color:blue;">if </span>(propertyInfo.CanRead)
            {
                <span style="color:blue;">this</span>.getValueHandler = <span style="color:blue;">this</span>.CreateGetValueHandler(propertyInfo);
            }

            <span style="color:blue;">if </span>(propertyInfo.CanWrite)
            {
                <span style="color:blue;">this</span>.setValueHandler = <span style="color:blue;">this</span>.CreateSetValueHandler(propertyInfo);
            }
        }

    <span style="color:blue;">public object </span>GetValue(<span style="color:blue;">object </span>component)
        {
            <span style="color:blue;">if </span>(<span style="color:blue;">this</span>.getValueHandler == <span style="color:blue;">null</span>)
            {
                <span style="color:blue;">throw new </span><span style="color:#2b91af;">InvalidOperationException</span>();
            }

            <span style="color:blue;">return this</span>.getValueHandler(component);
        }

    <span style="color:blue;">public void </span>SetValue(<span style="color:blue;">object </span>component, <span style="color:blue;">object </span>value)
        {
            <span style="color:blue;">if </span>(<span style="color:blue;">this</span>.setValueHandler == <span style="color:blue;">null</span>)
            {
                <span style="color:blue;">throw new </span><span style="color:#2b91af;">InvalidOperationException</span>();
            }

            <span style="color:blue;">this</span>.setValueHandler(component, value);
        }
}</pre>
<p>I measured the performance among the three approaches against 1 000 000 times invocation of one of the properties of the Employee entity class:</p>
<p><a href="http://ralch.files.wordpress.com/2011/02/diagram.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border-width:0;margin:0 0 10px;" title="diagram" border="0" alt="diagram" src="http://ralch.files.wordpress.com/2011/02/diagram_thumb.png?w=474&#038;h=274" width="474" height="274" /></a></p>
<p>Notice that the direct access approach followed by the Dynamic Methods implementation are the fastest.</p>
<p>You can download the <strong>PropertyAccessor</strong> class implementation <a href="https://sites.google.com/site/ralchrepository/sources/DynamicMethodAccess.zip?attredirects=0&amp;d=1" target="_blank">here</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ralch.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ralch.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ralch.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ralch.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ralch.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ralch.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ralch.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ralch.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ralch.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ralch.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ralch.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ralch.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ralch.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ralch.wordpress.com/326/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=326&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ralch.com/2011/02/06/fast-methods-emitting-with-dynamic-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fc622ca8108ba3e8faaa40486ebfb53?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ralch</media:title>
		</media:content>

		<media:content url="http://ralch.files.wordpress.com/2011/02/diagram_thumb.png" medium="image">
			<media:title type="html">diagram</media:title>
		</media:content>
	</item>
		<item>
		<title>How to prevent memory leaks when we are using events? (Part 1)</title>
		<link>http://blog.ralch.com/2010/01/21/how-to-prevent-memory-leaks-when-we-are-using-events/</link>
		<comments>http://blog.ralch.com/2010/01/21/how-to-prevent-memory-leaks-when-we-are-using-events/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 21:12:09 +0000</pubDate>
		<dc:creator>Svetlin Ralchev</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[CLR]]></category>
		<category><![CDATA[Design Patterns]]></category>

		<guid isPermaLink="false">http://ralch.wordpress.com/2010/01/21/how-to-prevent-memory-leaks-when-we-are-using-events/</guid>
		<description><![CDATA[In the average development lifecycle is possible that event handlers that are attached to events of sources to not be destroyed in coordination with the listener object that attached the handler to the source. Hence, this can lead to memory leaks. This cause the developers to take care about memory management not only when they <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=308&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the average development lifecycle is possible that event handlers that are attached to events of sources to not be destroyed in coordination with the listener object that attached the handler to the source. Hence, this can lead to memory leaks. This cause the developers to take care about memory management not only when they use unmanaged resources but also when they attach new event handlers to specified event.</p>
<p>This problem is scaled, when Microsoft ships Windows Presentation Foundation due to the lifecycle of visual element in the framework. They addressed this issue with implementation of <a href="http://msdn.microsoft.com/en-us/library/aa970850.aspx" target="_blank">Weak Event Design Pattern</a>.</p>
<p>But what should do if we are not using WPF? After my research regarding the pattern I realised that we need something which is more simple than porting or implementing the weak event pattern. My idea is to use Weak Reference object as host of each event that I want to be automatically memory managed by the GC. This may be easily achieved by generic class that will wraps event handler and make it possible to be used the same as event handlers are used. But unfortunately it could not be used in case of wrapping delegate, because GC will collect it on next collection. This happens, because nobody keeps reference to the method delegate.</p>
<p><strong>Design</strong></p>
<p>Lets create a generic class <em>WeakEventHandler&lt;TEventArgs&gt;</em>, which can received as type parameter only arguments inherited from <em>EventArgs</em> class. We will have 3 methods (for subscribe, unsubscribe and raise event). To make the class to look more natively as the trivial <em>EventHandler&lt;TEventArgs&gt; </em>we will create also operators +/- <em>with EventHandler&lt;TEventArgs&gt;</em> object.</p>
<p><a href="http://ralch.files.wordpress.com/2010/01/diagram.jpg"><img style="display:inline;border-width:0;" title="diagram" src="http://ralch.files.wordpress.com/2010/01/diagram_thumb.jpg?w=195&#038;h=240" border="0" alt="diagram" width="195" height="240" /></a></p>
<p>As you can see the overridden operators +/- are very useful. It looks like that you are using normal event handler. You should create the weak event handler as private field and expose it as public event property. This achieves that the user (the programmer that use your API) thinks that he is using a normal event.</p>
<p><strong>Conclusion</strong></p>
<p>Weak References gives a very flexible mechanism for memory management, which allows the Garbage Collector to collect all objects that have been subscribed for specified event and are not used anymore and not referenced by anybody. But they still don&#8217;t resolve the issue, because the delegate is collected on the next Garbage Collection.</p>
<p><strong>References</strong></p>
<p>After I created this article I searched in Google, regarding this approach and found several guys that has the similar or same ideas it before me. You may check their articles and approaches:</p>
<ul>
<li><a href="http://www.codeproject.com/KB/cs/WeakEvents.aspx" target="_blank">Weak Events in C# By Daniel Grunwald</a></li>
<li><a href="http://blog.technewlogic.de/post/Prevent-Net-Memory-Leaks-with-the-WeakEventManager.aspx" target="_blank">Prevent .Net Memory Leaks with the WeakEventManager by Ronald</a></li>
</ul>
<p>Note: I edited the article, because I don&#8217;t want to give a wrong example of using WeakReference class. See Part 2, where the right usage will be shown. In the first version I did a little joke to provoke people to write. Thanks to Beat Keiner that found what is wrong <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ralch.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ralch.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ralch.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ralch.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ralch.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ralch.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ralch.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ralch.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ralch.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ralch.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ralch.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ralch.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ralch.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ralch.wordpress.com/308/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=308&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ralch.com/2010/01/21/how-to-prevent-memory-leaks-when-we-are-using-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fc622ca8108ba3e8faaa40486ebfb53?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ralch</media:title>
		</media:content>

		<media:content url="http://ralch.files.wordpress.com/2010/01/diagram_thumb.jpg" medium="image">
			<media:title type="html">diagram</media:title>
		</media:content>
	</item>
		<item>
		<title>PInvoke: Getting all child handles of window</title>
		<link>http://blog.ralch.com/2009/12/05/pinvoke-getting-all-child-handles-of-window/</link>
		<comments>http://blog.ralch.com/2009/12/05/pinvoke-getting-all-child-handles-of-window/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 07:42:21 +0000</pubDate>
		<dc:creator>Svetlin Ralchev</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[PInvoke]]></category>
		<category><![CDATA[Winforms]]></category>

		<guid isPermaLink="false">http://blog.ralch.com/?p=295</guid>
		<description><![CDATA[If you don&#8217;t know I have a new job in Bulgaria. I went away form Web Development and now I&#8217;m working as Winforms Developer. However, we had a client that exceed the number of window handles (more than 10 000) due to bad design of application. While diagnosing his application, we needed to understand how <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=295&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you don&#8217;t know I have a new job in Bulgaria. I went away form Web Development and now I&#8217;m working as Winforms Developer. However, we had a client that exceed the number of window handles (more than 10 000) due to bad design of application. While diagnosing his application, we needed to understand how many handles are created and when they are born. <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Reading MSDN I figure out that Windows API provide the availability to get all child handles for specified handle. We should use unmanaged <em>EnumChildWindows</em><strong> </strong>function provided by user32.dll.</p>
<p><strong>MSDN Definition</strong></p>
<p><em>EnumChildWindows</em> function enumerates the child windows that belong to the specified parent window by passing the handle to each child window, in turn, to an application-defined callback function. <em>EnumChildWindows</em> continues until the last child window is enumerated or the callback function returns FALSE.</p>
<p><strong>Syntax</strong></p>
<p>BOOL EnumChildWindows(    <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; HWND hWndParent,     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; WNDENUMPROC lpEnumFunc,     <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; LPARAM lParam     <br />);</p>
<dl>
<dt><em>hWndParent</em> </dt>
<dt>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; [in] Handle to the parent window whose child windows are to be enumerated.<strong> </strong></dt>
<dt><em>lpEnumFunc</em> </dt>
<dd>[in] Pointer to an application-defined callback function. </dd>
<dt><em>lParam</em> </dt>
<dd>[in] Specifies an application-defined value to be passed to the callback function. </dd>
</dl>
<p><strong>Note:</strong> If a child window has created child windows of its own, <em>EnumChildWindows</em> enumerates those windows as well.</p>
<p><strong>How is used from .NET Framework</strong></p>
<div style="font-family:lucida console;background:white;color:black;font-size:8pt;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">WindowHandleInfo</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">private</span> <span style="color:blue;">delegate</span> <span style="color:blue;">bool</span> <span style="color:#2b91af;">EnumWindowProc</span>(<span style="color:#2b91af;">IntPtr</span> hwnd, <span style="color:#2b91af;">IntPtr</span> lParam);</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; [<span style="color:#2b91af;">DllImport</span>(<span style="color:#a31515;">&quot;user32&quot;</span>)]</p>
<p style="margin:0;">&#160;&#160;&#160; [<span style="color:blue;">return</span>: <span style="color:#2b91af;">MarshalAs</span>(<span style="color:#2b91af;">UnmanagedType</span>.Bool)]</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">private</span> <span style="color:blue;">static</span> <span style="color:blue;">extern</span> <span style="color:blue;">bool</span> EnumChildWindows(<span style="color:#2b91af;">IntPtr</span> window, <span style="color:#2b91af;">EnumWindowProc</span> callback, <span style="color:#2b91af;">IntPtr</span> lParam);</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">private</span> <span style="color:#2b91af;">IntPtr</span> _MainHandle;</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> WindowHandleInfo(<span style="color:#2b91af;">IntPtr</span> handle)</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">this</span>._MainHandle = handle;</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">IntPtr</span>&gt; GetAllChildHandles()</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">IntPtr</span>&gt; childHandles = <span style="color:blue;">new</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">IntPtr</span>&gt;();</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:#2b91af;">GCHandle</span> gcChildhandlesList = <span style="color:#2b91af;">GCHandle</span>.Alloc(childHandles);</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:#2b91af;">IntPtr</span> pointerChildHandlesList = <span style="color:#2b91af;">GCHandle</span>.ToIntPtr(gcChildhandlesList);</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">try</span></p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:#2b91af;">EnumWindowProc</span> childProc = <span style="color:blue;">new</span> <span style="color:#2b91af;">EnumWindowProc</span>(EnumWindow);</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; EnumChildWindows(<span style="color:blue;">this</span>._MainHandle, childProc, pointerChildHandlesList);</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">finally</span></p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; gcChildhandlesList.Free();</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">return</span> childHandles;</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">private</span> <span style="color:blue;">bool</span> EnumWindow(<span style="color:#2b91af;">IntPtr</span> hWnd, <span style="color:#2b91af;">IntPtr</span> lParam)</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:#2b91af;">GCHandle</span> gcChildhandlesList = <span style="color:#2b91af;">GCHandle</span>.FromIntPtr(lParam);</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">if</span> (gcChildhandlesList == <span style="color:blue;">null</span> || gcChildhandlesList.Target == <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">return</span> <span style="color:blue;">false</span>;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">IntPtr</span>&gt; childHandles = gcChildhandlesList.Target <span style="color:blue;">as</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:#2b91af;">IntPtr</span>&gt;;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; childHandles.Add(hWnd);</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">return</span> <span style="color:blue;">true</span>;</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">}</p>
</p></div>
<p><strong></strong></p>
<p>We are using <em>DLLImport</em> attribute to expose the method in .NET Environment. The specific point is that we create a handle to the list where are collected all pointers, due to availability to access it from the callback function where we know which is the child handle.</p>
<p><strong>References</strong></p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/ms633494%28VS.85%29.aspx" target="_blank">MSDN</a> </li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ralch.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ralch.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ralch.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ralch.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ralch.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ralch.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ralch.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ralch.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ralch.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ralch.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ralch.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ralch.wordpress.com/295/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ralch.wordpress.com/295/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ralch.wordpress.com/295/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=295&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ralch.com/2009/12/05/pinvoke-getting-all-child-handles-of-window/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fc622ca8108ba3e8faaa40486ebfb53?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ralch</media:title>
		</media:content>
	</item>
		<item>
		<title>Snowflake Framework was born</title>
		<link>http://blog.ralch.com/2009/10/22/snowflake-framwork-is-born/</link>
		<comments>http://blog.ralch.com/2009/10/22/snowflake-framwork-is-born/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 10:04:03 +0000</pubDate>
		<dc:creator>Svetlin Ralchev</dc:creator>
				<category><![CDATA[Bulletin]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://blog.ralch.com/?p=286</guid>
		<description><![CDATA[I&#8217;m glad to announce Snowflake Framework. I&#8217;m the founder and main contributor. I hope that will find other fellows that will be involved it the project. Initally it&#8217;s lightweight data access framework based on LINQ TO SQL. You can find more information about it at http://snowflake.codeplex.com<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=286&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m glad to announce Snowflake Framework. I&#8217;m the founder and main contributor. I hope that will find other fellows that will be involved it the project. Initally it&#8217;s lightweight data access framework based on LINQ TO SQL.<br />
You can find more information about it at <a href="http://snowflake.codeplex.com/">http://snowflake.codeplex.com</a>.<br />
<a href="http://snowflake.codeplex.com/"><img src="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=CodePlex&amp;DownloadId=3878" alt="Code Plex" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ralch.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ralch.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ralch.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ralch.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ralch.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ralch.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ralch.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ralch.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ralch.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ralch.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ralch.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ralch.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ralch.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ralch.wordpress.com/286/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=286&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ralch.com/2009/10/22/snowflake-framwork-is-born/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fc622ca8108ba3e8faaa40486ebfb53?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ralch</media:title>
		</media:content>

		<media:content url="http://i3.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=CodePlex&#38;DownloadId=3878" medium="image">
			<media:title type="html">Code Plex</media:title>
		</media:content>
	</item>
		<item>
		<title>ADO.NET: XMLSerialization of extended DataTable</title>
		<link>http://blog.ralch.com/2009/10/18/ado-net-xmlserialization-of-extended-datatable/</link>
		<comments>http://blog.ralch.com/2009/10/18/ado-net-xmlserialization-of-extended-datatable/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 14:12:46 +0000</pubDate>
		<dc:creator>Svetlin Ralchev</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[ADO.NET]]></category>

		<guid isPermaLink="false">http://blog.ralch.com/?p=267</guid>
		<description><![CDATA[Before 1,5 year I worked on the project, where we move all communication logic from .NET Remoting to WCF. In the architecture of the project our common transportation object is derived from Data Table. Due to some business rules this class has some additional fields. In .NET Remoting serialization of that kind of object works <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=267&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Before 1,5 year I worked on the project, where we move all communication logic from .NET Remoting to WCF. In the architecture of the project our common transportation object is derived from Data Table. Due to some business rules this class has some additional fields. In .NET Remoting serialization of that kind of object works perfectly, but in WCF these additional fields isn’t serialized. The problem is due to changes serialization mechanism. Instead of binary serialization in .NET Remoting, in WCF serialization is XML based. In trying to solve this issue I created a <a href="http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/0ea17391-97fc-4a2e-95dd-81edf6bc1ab0" target="_blank">post</a> in MSDN Forums. Despite of that I found out the solution. This article explain my solution and give the community more clear view how to do it, instead of looking my old post in MSDN.</p>
<p>Lets say that we have this class that derives Data Table:</p>
<div style="font-family:lucida console;background:white;color:black;font-size:8pt;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">WcfDataTable</span> : <span style="color:#2b91af;">DataTable</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">private</span> <span style="color:blue;">string</span> _ServerName;</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:#2b91af;">WcfDataTable</span>()</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; : <span style="color:blue;">base</span>()</p>
<p style="margin:0;">&#160;&#160;&#160; { }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:#2b91af;">WcfDataTable</span>(<span style="color:blue;">string</span> tableName)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; : <span style="color:blue;">base</span>(tableName)</p>
<p style="margin:0;">&#160;&#160;&#160; { }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">string</span> ServerName</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">get</span> { <span style="color:blue;">return</span> <span style="color:blue;">this</span>._ServerName; }</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">set</span> { <span style="color:blue;">this</span>._ServerName = <span style="color:blue;">value</span>; }</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">}</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">Lets serialize instance of this class using XMLSerializer:<a href="http://ralch.files.wordpress.com/2009/10/wcf_table_screen.jpg"><img style="display:inline;border-width:0;" title="wcf_table_screen" border="0" alt="wcf_table_screen" src="http://ralch.files.wordpress.com/2009/10/wcf_table_screen_thumb.jpg?w=551&#038;h=283" width="551" height="283" /></a> </p>
</p></div>
</p>
<p>As you can see I’m creating dummy WcfDataTable object, which I’m cloning using xml serialization and deserialization. The cloned object is not identical with the original object, because this additional field is not initialized with the original value (it’s null). The existing xml serialization doesn’t catch the new field in the class. To make possible this field for xml serialization we should override the existing xml serialization, but how to do it? The solution is really simple. You have to implement the interface IXmlSerializable with explicit override of all its methods. </p>
<div style="font-family:lucida console;background:white;color:black;font-size:8pt;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">WcfDataTable</span> : <span style="color:#2b91af;">DataTable</span>, <span style="color:#2b91af;">IXmlSerializable</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">private</span> <span style="color:blue;">string</span> _ServerName;</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:#2b91af;">WcfDataTable</span>()</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; : <span style="color:blue;">base</span>()</p>
<p style="margin:0;">&#160;&#160;&#160; { }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:#2b91af;">WcfDataTable</span>(<span style="color:blue;">string</span> tableName)</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; : <span style="color:blue;">base</span>(tableName)</p>
<p style="margin:0;">&#160;&#160;&#160; { }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">public</span> <span style="color:blue;">string</span> ServerName</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">get</span> { <span style="color:blue;">return</span> <span style="color:blue;">this</span>._ServerName; }</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">set</span> { <span style="color:blue;">this</span>._ServerName = <span style="color:blue;">value</span>; }</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">void</span> <span style="color:#2b91af;">IXmlSerializable</span>.ReadXml(System.Xml.<span style="color:#2b91af;">XmlReader</span> reader)</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">base</span>.ReadXmlSchema(reader);</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:#2b91af;">XmlSerializer</span> xmlSerializer = <span style="color:blue;">new</span> <span style="color:#2b91af;">XmlSerializer</span>(<span style="color:blue;">typeof</span>(<span style="color:blue;">string</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">this</span>._ServerName = xmlSerializer.Deserialize(reader) <span style="color:blue;">as</span> <span style="color:blue;">string</span>;</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">base</span>.ReadXml(reader);</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160; <span style="color:blue;">void</span> <span style="color:#2b91af;">IXmlSerializable</span>.WriteXml(System.Xml.<span style="color:#2b91af;">XmlWriter</span> writer)</p>
<p style="margin:0;">&#160;&#160;&#160; {</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">base</span>.WriteXmlSchema(writer);</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:#2b91af;">XmlSerializer</span> xmlSerializer = <span style="color:blue;">new</span> <span style="color:#2b91af;">XmlSerializer</span>(<span style="color:blue;">typeof</span>(<span style="color:blue;">string</span>));</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; xmlSerializer.Serialize(writer, <span style="color:blue;">this</span>._ServerName);</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color:blue;">base</span>.WriteXml(writer, <span style="color:#2b91af;">XmlWriteMode</span>.DiffGram);</p>
<p style="margin:0;">&#160;&#160;&#160; }</p>
<p style="margin:0;">}</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;">To do this workaround we have to override WriteXml and ReadXml method explicitly. The methods ReadXmlSchema and WriteXmlSchema are used to read and write the schema of data table, then we can read or write our data. Hence we can write/read our new field and then to invoke basic logic for serialization or deserializtion. So we reach our goal:</p>
<p style="margin:0;">&#160;</p>
<p style="margin:0;"><a href="http://ralch.files.wordpress.com/2009/10/wcf_table_screen_done.jpg"><img style="border-bottom:0;border-left:0;display:inline;border-top:0;border-right:0;" title="wcf_table_screen_done" border="0" alt="wcf_table_screen_done" src="http://ralch.files.wordpress.com/2009/10/wcf_table_screen_done_thumb.jpg?w=590&#038;h=277" width="590" height="277" /></a> </p>
</p></div>
</p>
<p>After this workaround you can see that our new field is serialized and deserialized successfully.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ralch.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ralch.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ralch.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ralch.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ralch.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ralch.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ralch.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ralch.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ralch.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ralch.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ralch.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ralch.wordpress.com/267/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ralch.wordpress.com/267/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ralch.wordpress.com/267/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=267&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ralch.com/2009/10/18/ado-net-xmlserialization-of-extended-datatable/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fc622ca8108ba3e8faaa40486ebfb53?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ralch</media:title>
		</media:content>

		<media:content url="http://ralch.files.wordpress.com/2009/10/wcf_table_screen_thumb.jpg" medium="image">
			<media:title type="html">wcf_table_screen</media:title>
		</media:content>

		<media:content url="http://ralch.files.wordpress.com/2009/10/wcf_table_screen_done_thumb.jpg" medium="image">
			<media:title type="html">wcf_table_screen_done</media:title>
		</media:content>
	</item>
		<item>
		<title>LINQ to help: Create generic method to load entity by primary key</title>
		<link>http://blog.ralch.com/2009/10/11/how-to-linq-create-generic-method-to-load-entity-by-primary-key/</link>
		<comments>http://blog.ralch.com/2009/10/11/how-to-linq-create-generic-method-to-load-entity-by-primary-key/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 20:13:45 +0000</pubDate>
		<dc:creator>Svetlin Ralchev</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[ADO.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://ralch.wordpress.com/?p=158</guid>
		<description><![CDATA[After a short chat with my ex-colleague asking me to help him to create generic method that loads any entity class from the database I decided to write this article in case of somebody needs the same in his project. By the way thank you Teodor for my inspiration to do it. Scenario We are <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=158&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After a short chat with my ex-colleague asking me to help him to create generic method that loads any entity class from the database I decided to write this article in case of somebody needs the same in his project. By the way thank you Teodor for my inspiration to do it.</p>
<p><em><strong>Scenario</strong></em></p>
<p>We are implementing our data access layer based on LINQ TO SQL. In the specifications that were created by our software architect is required to have generic method that load from the data base any record into entity object by primary key.</p>
<div style="font-family:Lucida Console;font-size:8pt;color:black;">
<p style="margin:0;"><span style="color:blue;">public</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">LINQGateway</span>&lt;TEntity&gt; <span style="color:blue;">where</span> TEntity : <span style="color:blue;">class</span></p>
<p style="margin:0;">{</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">private</span> <span style="color:#2b91af;">IDbConnection</span> _DbConnection;</p>
<p style="margin:0;">
<p style="margin:0;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">public</span> LINQGateway(<span style="color:#2b91af;">IDbConnection</span> connection)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp;&nbsp;{</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">this</span>._DbConnection = connection;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p style="margin:0;">
<p style="margin:0;">&nbsp;&nbsp;&nbsp;&nbsp;<span style="color:blue;">public</span> TEntity GetEntityByPrimaryKey(<span style="color:blue;">object</span> pkKey, <span style="color:blue;">params</span> <span style="color:blue;">object</span>[] pkKeys)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp;&nbsp;{</p>
<p style="color:Green;margin:0;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// TO DO</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p style="margin:0;">}</p>
<p style="margin:0;">&nbsp;</p>
</div>
<p><em><strong>Problem</strong></em></p>
<p>We become stuck, because each table has different primary key (count, name and data type of the primary key columns). So how to create a method that can be used in any case of  loading a record from the database by primary key. So we are facing the challenge how to implement <em>GetEntityByPrimaryKey</em>.</p>
<p><strong><em>The Algorithm</em></strong></p>
<p>1. Get tha mapping of the entity type<br />
2. Use information for the mapping<br />
&nbsp;&nbsp;2.1 to get the name of the columns<br />
&nbsp;&nbsp;2.2 to get the name of the columns included in the primary key<br />
3. Generate the T-SQL Query<br />
4. Execute the Query via LINQ Framework to retrive the result as entity object</p>
<p>Before explain my approach to implement the algorithm above I want to explain you how linq expressions are executed.</p>
<p><em><strong>Implementation and Solutions</strong></em></p>
<p>I figured out 2 soltuions that are almost the same. The first solution (the simplest one) uses standard T-SQL that is translated by LINQ. The second one is using dynamic lambda expressions to build LINQ Query that is used to get the entity from the database.</p>
<p><strong><em>Solution No.1</em></strong></p>
<p>This is the easiest and simple way to get a entity by primary key. This is the solution that I gave to my colleague.</p>
<div style="font-family:Lucida Console;font-size:8pt;color:black;">
<p style="margin:0;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:blue;">public</span> TEntity GetEntityByPrimaryKey(<span style="color:blue;">object</span> pkKey, <span style="color:blue;">params</span> <span style="color:blue;">object</span>[] pkKeys)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">List</span>&lt;<span style="color:blue;">object</span>&gt; primaryKeys = <span style="color:blue;">new</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:blue;">object</span>&gt;();</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; primaryKeys.Add(pkKey);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; primaryKeys.AddRange(pkKeys);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; TEntity entity = <span style="color:blue;">null</span>;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">Type</span> entityType = <span style="color:blue;">typeof</span>(TEntity);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">using</span> (<span style="color:#2b91af;">DataContext</span> dataContext = <span style="color:blue;">new</span> <span style="color:#2b91af;">DataContext</span>(<span style="color:blue;">this</span>._DbConnection))</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dataContext.Log = <span style="color:blue;">new</span> <span style="color:#2b91af;">DebuggerWriter</span>();</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dataContext.ObjectTrackingEnabled = <span style="color:blue;">false</span>;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">Table</span>&lt;TEntity&gt; table = dataContext.GetTable&lt;TEntity&gt;();</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">MetaType</span> metaEntityType = dataContext.Mapping.GetMetaType(entityType);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">var</span> primaryKeyColumns = <span style="color:blue;">from</span> pkColumn <span style="color:blue;">in</span> metaEntityType.DataMembers</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">where</span> pkColumn.IsPrimaryKey</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">select</span> pkColumn;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">var</span> columns = <span style="color:blue;">from</span> col <span style="color:blue;">in</span> metaEntityType.DataMembers</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color:blue;">where</span> col.IsPersistent &amp;&amp; !col.IsAssociation</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color:blue;">orderby</span> col.Ordinal</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; <span style="color:blue;">select</span> <span style="color:#a31515;">&quot;[t0].[&quot;</span> + col.MappedName + <span style="color:#a31515;">&quot;]&quot;</span>;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">string</span> selectColumns = <span style="color:#2b91af;">String</span>.Join(<span style="color:#a31515;">&quot;, &quot;</span>, columns.ToArray());</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">int</span> pkColumnsCount = 0;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">if</span> (primaryKeyColumns != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pkColumnsCount = primaryKeyColumns.Count();</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">if</span> (pkColumnsCount == 0)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">throw</span> <span style="color:blue;">new</span> <span style="color:#2b91af;">InvalidOperationException</span>(<span style="color:#a31515;">&quot;Table doesn&#8217;t have primary key&quot;</span>);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">if</span> (pkColumnsCount != primaryKeys.Count)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">throw</span> <span style="color:blue;">new</span> <span style="color:#2b91af;">InvalidOperationException</span>(<span style="color:#a31515;">&quot;Primary key values doesn&#8217;t match primary key columns.&quot;</span>);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">string</span> tableName = metaEntityType.Table.TableName;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">if</span> (tableName.Contains(<span style="color:#a31515;">&#8216;.&#8217;</span>))</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">string</span>[] splittedTablename = metaEntityType.Table.TableName.Split(<span style="color:#a31515;">&#8216;.&#8217;</span>).Select(p =&gt; <span style="color:#a31515;">&quot;[&quot;</span> + p + <span style="color:#a31515;">&quot;]&quot;</span>).ToArray();</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; tableName = <span style="color:#2b91af;">String</span>.Join(<span style="color:#a31515;">&quot;.&quot;</span>, splittedTablename);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">StringBuilder</span> builder = <span style="color:blue;">new</span> <span style="color:#2b91af;">StringBuilder</span>(<span style="color:#a31515;">&quot;SELECT &quot;</span> + selectColumns + <span style="color:#2b91af;">Environment</span>.NewLine + <span style="color:#a31515;">&quot;FROM &quot;</span> + tableName + <span style="color:#a31515;">&quot; AS [t0]&quot;</span> + <span style="color:#2b91af;">Environment</span>.NewLine + <span style="color:#a31515;">&quot;WHERE &quot;</span>);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">int</span> index = 0;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">foreach</span> (<span style="color:#2b91af;">MetaDataMember</span> pkColumn <span style="color:blue;">in</span> primaryKeyColumns)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">string</span> columnName = pkColumn.Name;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">string</span> paramID = index.ToString(<span style="color:#2b91af;">CultureInfo</span>.InvariantCulture);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; builder.Append(<span style="color:#a31515;">&quot;[t0].[&quot;</span> + columnName + <span style="color:#a31515;">&quot;] = {&quot;</span> + paramID + <span style="color:#a31515;">&quot;}&quot;</span>);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">if</span> (index + 1 != pkColumnsCount)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; builder.Append(<span style="color:#a31515;">&quot; AND &quot;</span>);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; index++;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">string</span> query = builder.ToString();</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; entity = dataContext.ExecuteQuery&lt;TEntity&gt;(query, primaryKeys.ToArray()).SingleOrDefault();</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">return</span> entity;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;</p>
</div>
<p><strong><em>Solution No.2</em></strong></p>
<p>This is the solution is more complicated than the one above.</p>
<div style="font-family:Lucida Console;font-size:8pt;color:black;">
<p style="margin:0;"><span style="color:blue;">public</span> TEntity GetEntityByPrimaryKey(<span style="color:blue;">object</span> pkKey, <span style="color:blue;">params</span> <span style="color:blue;">object</span>[] pkKeys)</p>
<p style="margin:0;">{</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">List</span>&lt;<span style="color:blue;">object</span>&gt; primaryKeys = <span style="color:blue;">new</span> <span style="color:#2b91af;">List</span>&lt;<span style="color:blue;">object</span>&gt;();</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; primaryKeys.Add(pkKey);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; primaryKeys.AddRange(pkKeys);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; TEntity entity = <span style="color:blue;">null</span>;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">Type</span> entityType = <span style="color:blue;">typeof</span>(TEntity);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; <span style="color:blue;">using</span> (<span style="color:#2b91af;">DataContext</span> dataContext = <span style="color:blue;">new</span> <span style="color:#2b91af;">DataContext</span>(<span style="color:blue;">this</span>._DbConnection))</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dataContext.Log = <span style="color:blue;">new</span> <span style="color:#2b91af;">DebuggerWriter</span>();</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; dataContext.ObjectTrackingEnabled = <span style="color:blue;">false</span>;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">Table</span>&lt;TEntity&gt; table = dataContext.GetTable&lt;TEntity&gt;();</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">MetaType</span> metaEntityType = dataContext.Mapping.GetMetaType(entityType);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">var</span> primaryKeyColumns = <span style="color:blue;">from</span> pkColumn <span style="color:blue;">in</span> metaEntityType.DataMembers</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">where</span> pkColumn.IsPrimaryKey</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">select</span> pkColumn;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">int</span> pkColumnsCount = 0;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">if</span> (primaryKeyColumns != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pkColumnsCount = primaryKeyColumns.Count();</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">if</span> (pkColumnsCount == 0)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">throw</span> <span style="color:blue;">new</span> <span style="color:#2b91af;">InvalidOperationException</span>(<span style="color:#a31515;">&quot;Table doesn&#8217;t have primary key&quot;</span>);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">if</span> (pkColumnsCount != primaryKeys.Count)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">throw</span> <span style="color:blue;">new</span> <span style="color:#2b91af;">InvalidOperationException</span>(<span style="color:#a31515;">&quot;Primary key value doesn&#8217;t match primary key columns.&quot;</span>);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">ParameterExpression</span> paramExpression = <span style="color:#2b91af;">Expression</span>.Parameter(entityType, <span style="color:#a31515;">&quot;entity&quot;</span>);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">BinaryExpression</span> whereExpression = <span style="color:blue;">null</span>;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">int</span> index = 0;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">foreach</span> (<span style="color:#2b91af;">MetaDataMember</span> pkColumn <span style="color:blue;">in</span> primaryKeyColumns)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">object</span> value = primaryKeys[index];</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">string</span> columnName = pkColumn.Name;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">if</span> (value != <span style="color:blue;">null</span> &amp;&amp; value.GetType() != pkColumn.Type)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">Type</span> paramType = value.GetType();</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">string</span> exceptionMsg = <span style="color:#2b91af;">String</span>.Format(<span style="color:#a31515;">&quot;The type &#8216;{0}&#8217; of parameter &#8216;{1}&#8217; is different than its column &#8216;{2}&#8217; type &#8216;{3}&#8217;&quot;</span>, paramType, value, columnName, pkColumn.Type);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">throw</span> <span style="color:blue;">new</span> <span style="color:#2b91af;">InvalidOperationException</span>(exceptionMsg);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">BinaryExpression</span> condition = <span style="color:#2b91af;">Expression</span>.Equal(<span style="color:#2b91af;">Expression</span>.Property(paramExpression, columnName), <span style="color:#2b91af;">Expression</span>.Constant(value));</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">if</span> (whereExpression != <span style="color:blue;">null</span>)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; whereExpression = <span style="color:#2b91af;">Expression</span>.And(whereExpression, condition);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">else</span></p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; whereExpression = condition;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; index++;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:#2b91af;">Expression</span>&lt;<span style="color:#2b91af;">Func</span>&lt;TEntity, <span style="color:blue;">bool</span>&gt;&gt; predicate = <span style="color:#2b91af;">Expression</span>.Lambda&lt;<span style="color:#2b91af;">Func</span>&lt;TEntity, <span style="color:blue;">bool</span>&gt;&gt;(whereExpression, <span style="color:blue;">new</span> <span style="color:#2b91af;">ParameterExpression</span>[] { paramExpression });</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; entity = table.SingleOrDefault(predicate);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; <span style="color:blue;">return</span> entity;</p>
<p style="margin:0;">}</p>
<p style="margin:0;">&nbsp;</p>
</div>
<p><em><strong>Conclusion</strong></em></p>
<p>&nbsp;&nbsp;In Solution No.1 we generate T-SQL string that is executed by LINQ and the result is translated as entity object. Insead of this in Solution No.2 we created dynamic LINQ expression that is translated by LINQ TO SQL Framework to T-SQL, which expected to be costly. So I did some tests in Northwind database to prove my expectations.<br />
&nbsp;&nbsp;Solution No.1 loads 1 record from table Employees for 315 milliseconds (average speed) againts 292 milliseconds (average speed) for Solution No.2. So I can&#8217;t say which implementation is the best way to resolve the task. Presently I&#8217;m in doubt about that. Why solution no.2 is faster than Solution no.1? I hope that I will give the aswer of this question soon in further posts.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ralch.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ralch.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ralch.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ralch.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ralch.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ralch.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ralch.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ralch.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ralch.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ralch.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ralch.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ralch.wordpress.com/158/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ralch.wordpress.com/158/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ralch.wordpress.com/158/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=158&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ralch.com/2009/10/11/how-to-linq-create-generic-method-to-load-entity-by-primary-key/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fc622ca8108ba3e8faaa40486ebfb53?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ralch</media:title>
		</media:content>
	</item>
		<item>
		<title>My Home Workstation</title>
		<link>http://blog.ralch.com/2009/10/01/my-home-workstation/</link>
		<comments>http://blog.ralch.com/2009/10/01/my-home-workstation/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 10:47:10 +0000</pubDate>
		<dc:creator>Svetlin Ralchev</dc:creator>
				<category><![CDATA[Bulletin]]></category>

		<guid isPermaLink="false">http://blog.ralch.com/?p=231</guid>
		<description><![CDATA[<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=231&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://ralch.files.wordpress.com/2009/10/dsc007121.jpg"><img class="aligncenter size-medium wp-image-229" title="DSC00712" src="http://ralch.files.wordpress.com/2009/10/dsc007121.jpg?w=504&#038;h=379" alt="DSC00712" width="504" height="379" /></a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ralch.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ralch.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ralch.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ralch.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ralch.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ralch.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ralch.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ralch.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ralch.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ralch.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ralch.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ralch.wordpress.com/231/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ralch.wordpress.com/231/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ralch.wordpress.com/231/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=231&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ralch.com/2009/10/01/my-home-workstation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fc622ca8108ba3e8faaa40486ebfb53?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ralch</media:title>
		</media:content>

		<media:content url="http://ralch.files.wordpress.com/2009/10/dsc007121.jpg?w=300" medium="image">
			<media:title type="html">DSC00712</media:title>
		</media:content>
	</item>
		<item>
		<title>Happy new name, dear blog</title>
		<link>http://blog.ralch.com/2009/09/11/happy-new-name-dear-blog/</link>
		<comments>http://blog.ralch.com/2009/09/11/happy-new-name-dear-blog/#comments</comments>
		<pubDate>Fri, 11 Sep 2009 08:43:49 +0000</pubDate>
		<dc:creator>Svetlin Ralchev</dc:creator>
				<category><![CDATA[Bulletin]]></category>

		<guid isPermaLink="false">http://blog.ralch.com/?p=220</guid>
		<description><![CDATA[As you see, my blog has new domain name. Instead of the old one http://ralch.wordpress.com I bought http://blog.ralch.com. My blog will be part of my domain http://www.ralch.com where I&#8217;ll try to contribute to the whole internet community with my professional work as software developer and sharing my hobbies and experiences<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=220&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>As you see, my blog has new domain name. Instead of the old one http://ralch.wordpress.com I bought http://blog.ralch.com. My blog will be part of my domain http://www.ralch.com where I&#8217;ll try to contribute to the whole internet community with my professional work as software developer and sharing my hobbies and experiences.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ralch.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ralch.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ralch.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ralch.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ralch.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ralch.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ralch.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ralch.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ralch.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ralch.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ralch.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ralch.wordpress.com/220/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ralch.wordpress.com/220/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ralch.wordpress.com/220/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=220&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ralch.com/2009/09/11/happy-new-name-dear-blog/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fc622ca8108ba3e8faaa40486ebfb53?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ralch</media:title>
		</media:content>
	</item>
		<item>
		<title>Funny C# Code</title>
		<link>http://blog.ralch.com/2009/08/11/funny-c-code/</link>
		<comments>http://blog.ralch.com/2009/08/11/funny-c-code/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 09:46:02 +0000</pubDate>
		<dc:creator>Svetlin Ralchev</dc:creator>
				<category><![CDATA[Bulletin]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://ralch.wordpress.com/?p=139</guid>
		<description><![CDATA[Even though I don&#8217;t know the author of the lines below I would say &#8220;Thank you man&#8221;. I recieved them today on skype by one of my ex-collegues. &#160;&#160;&#160; &#160;&#160;&#160;&#160;try &#160;&#160;&#160; &#160;&#160;&#160; { &#160;&#160;&#160; &#160;&#160;&#160; HOME: &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; do &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; { &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; Play(&#8220;World of Warcraft&#8221;); &#160;&#160;&#160; &#160;&#160;&#160; &#160;&#160;&#160; } <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=139&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Even though I don&#8217;t know the author of the lines below I would say &#8220;Thank you man&#8221;. I recieved them today on skype by one of my ex-collegues.</p>
<div style="font-family:Lucida Console;font-size:9pt;color:black;background:white;">
<p style="margin:0;"><span style="color:blue;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;try</span></p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; HOME:</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">do</span></p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Play(<span style="color:maroon;">&#8220;World of Warcraft&#8221;</span>);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">while</span> (!asleep);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:teal;">Thread</span>.Sleep(12 * 60 * 60 * 1000);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; WakeUp(coffee);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">if</span> (you_still_give_a_shit())</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">goto</span> WORK;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">else</span></p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">goto</span> OUT;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; WORK:</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">do</span></p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">if</span> (got_something_to_do())</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; LookAtTheMonitor();</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Press_Some_Keys(<span style="color:blue;">new</span> <span style="color:blue;">string</span>[] { <span style="color:maroon;">&#8220;Ctrl+C&#8221;</span>, <span style="color:maroon;">&#8220;Ctrl+V&#8221;</span> });</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Browse(<span style="color:maroon;">&#8220;vbox7.com&#8221;</span>);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Browse(<span style="color:maroon;">&#8220;topsport.bg&#8221;</span>);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Browse(<span style="color:maroon;">&#8220;youtube.com&#8221;</span>);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Have_a_Break();</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Have_a_Kitkat();</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">while</span> (<span style="color:teal;">DateTime</span>.Now.Hour &lt; 5);</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">if</span> (<span style="color:teal;">DateTime</span>.Now.Day == 1)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:green;">// at least</span></p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; GetSomeCash(3000);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; OUT:</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">switch</span> (mood)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">case</span> <span style="color:teal;">Mood</span>.Horny:</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ChaseChicks(<span style="color:maroon;">&#8220;hot!&#8221;</span>);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">break</span>;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">case</span> <span style="color:teal;">Mood</span>.Dull:</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SmokeSomeStuff(<span style="color:blue;">new</span> <span style="color:teal;">Stuff</span>[] { <span style="color:maroon;">&#8220;Grass&#8221;</span>, <span style="color:maroon;">&#8220;Serious Stuff&#8221;</span> });</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">break</span>;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">default</span>:</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; DrinkBeer(5);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">break</span>;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">goto</span> HOME;</p>
<p style="margin:0;">&nbsp;</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">catch</span> (<span style="color:teal;">HealthException</span> x)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; SeeTheDoctor(x);</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <span style="color:blue;">catch</span> (<span style="color:teal;">NoMoneyException</span>)</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ShitHappens();</p>
<p style="margin:0;">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ralch.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ralch.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ralch.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ralch.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ralch.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ralch.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ralch.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ralch.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ralch.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ralch.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ralch.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ralch.wordpress.com/139/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ralch.wordpress.com/139/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ralch.wordpress.com/139/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.ralch.com&amp;blog=5597926&amp;post=139&amp;subd=ralch&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.ralch.com/2009/08/11/funny-c-code/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9fc622ca8108ba3e8faaa40486ebfb53?s=96&#38;d=&#38;r=G" medium="image">
			<media:title type="html">ralch</media:title>
		</media:content>
	</item>
	</channel>
</rss>
