<?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:creativeCommons="http://backend.userland.com/creativeCommonsRssModule">

<channel>
	<title>techencoder &#187; C#</title>
	<atom:link href="http://techencoder.com/index.php/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://techencoder.com</link>
	<description>Technical ideas in a human readable format</description>
	<lastBuildDate>Wed, 01 Feb 2012 17:19:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<creativeCommons:license>http://creativecommons.org/licenses/by/3.0/us/</creativeCommons:license>		<item>
		<title>Getting DataTables to work with ASP.Net MVC</title>
		<link>http://techencoder.com/index.php/2009/12/getting-datatables-to-work-with-asp-net-mvc/</link>
		<comments>http://techencoder.com/index.php/2009/12/getting-datatables-to-work-with-asp-net-mvc/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 07:13:12 +0000</pubDate>
		<dc:creator>r.claypool</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[DataTables]]></category>

		<guid isPermaLink="false">http://techencoder.com/?p=1041</guid>
		<description><![CDATA[Want to get jQuery DataTables to work in an ASP.Net MVC project ??? Here is a demo project in C# that should get you started.  If I find the time, I&#8217;ll post details on how this was put together (but I think most developers will benefit more from running and stepping through the source code [...]]]></description>
			<content:encoded><![CDATA[<p>Want to get jQuery <a href="http://www.datatables.net/">DataTables</a> to work in an ASP.Net MVC project ???</p>
<p>Here is a <a href="http://techencoder.com/wp-content/uploads/2009/12/ASP.Net-MVC-and-DataTables-Demo.zip">demo project</a> in C# that should get you started.  If I find the time, I&#8217;ll post details on how this was put together (but I think most developers will benefit more from running and stepping through the source code anyway).</p>
<p>Hope this helps someone.  Happy Programming!</p>
]]></content:encoded>
			<wfw:commentRss>http://techencoder.com/index.php/2009/12/getting-datatables-to-work-with-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LINQ-To-SQL DataContext and NullReferenceException</title>
		<link>http://techencoder.com/index.php/2009/06/linq-to-sql-datacontext-and-nullreferenceexception/</link>
		<comments>http://techencoder.com/index.php/2009/06/linq-to-sql-datacontext-and-nullreferenceexception/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 16:57:41 +0000</pubDate>
		<dc:creator>r.claypool</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://techencoder.com/?p=763</guid>
		<description><![CDATA[LINQ classes generated by the VS designer (or sqlmetal.exe) are marked partial by default. &#91;System.Data.Linq.Mapping.DatabaseAttribute&#40;Name=&#34;MyData&#34;&#41;&#93; public partial class MyDataDataContext : System.Data.Linq.DataContext &#123; // blah ... blah ... &#125; public partial class MyDataDataContext &#123; // My additional methods, constructors, etc. &#125; As I&#8217;ve shown above, this allows you to extend a class without modifying the original [...]]]></description>
			<content:encoded><![CDATA[<p>LINQ classes generated by the VS designer (or <a title="Code Generation Tool (SqlMetal.exe)" href="http://msdn.microsoft.com/en-us/library/bb386987.aspx">sqlmetal.exe</a>) are marked partial by default.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Data</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Linq</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Mapping</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DatabaseAttribute</span><span style="color: #008000;">&#40;</span>Name<span style="color: #008000;">=</span><span style="color: #666666;">&quot;MyData&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#93;</span>
<span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyDataDataContext <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Data</span></span><span style="color: #008000;">.</span><span style="color: #0000FF;">Linq</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DataContext</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// blah ... blah ...</span>
<span style="color: #008000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyDataDataContext
<span style="color: #008000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">// My additional methods, constructors, etc.</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>As I&#8217;ve shown above, this allows you to extend a class without modifying the original code.  The <a title="Partial Class Definitions at MSDN" href="http://msdn.microsoft.com/en-us/library/wa80x488(VS.80).aspx">additional class definitions</a> just live somewhere else, typically in another file, and the compiler integrates them as needed.  That&#8217;s great for keeping your code out of the machine generated file, but you still need to be aware of what the machine generated code is doing before you extend it!  One thing to check is the default (sqlmetal generated) constructor when you are planning to overload it with your own. <strong>In some cases, the default constructor will initialize dependencies, so if you write an overload, make sure it calls the default constructor too:</strong></p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">partial</span> <span style="color: #6666cc; font-weight: bold;">class</span> MyDataDataContext
<span style="color: #008000;">&#123;</span>
    <span style="color: #0600FF; font-weight: bold;">public</span> MyDataContext<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #0600FF; font-weight: bold;">this</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008080; font-style: italic;">// We must call the designer generated constructor because it contains initialization code.</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// blah ... blah ...</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Notice how I used the constructor initialization keyword <code>: this()</code>.<br />
From the C# Specification <a href="http://msdn.microsoft.com/en-us/library/aa645603(VS.71).aspx">Section 10.10.1</a></p>
<div style="padding-left:30px; color:Chocolate"><strong>&#8220;An instance constructor initializer of the form this(argument-listopt) causes an instance constructor from the class itself to be invoked.&#8221;</strong></div>
<div style="padding-top:10px">If your DataContext is throwing a NullReferenceException <em>&#8220;Object reference not set to an instance of an object&#8221;</em>,  make sure you are calling the default constructor.</div>
<div id="attachment_764" class="wp-caption aligncenter" style="width: 610px"><img class="size-full wp-image-764" title="null-reference-exception" src="http://techencoder.com/wp-content/uploads/2009/06/null-reference-exception.png" alt="Don't forget to call the default constructor!" width="600" height="255" /><p class="wp-caption-text">Don&#39;t forget to call the default constructor!</p></div>
<p>Happy Coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://techencoder.com/index.php/2009/06/linq-to-sql-datacontext-and-nullreferenceexception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

