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

<channel>
	<title>Codelab Blog &#187; Subsonic</title>
	<atom:link href="http://blog.codelab.co.nz/tag/subsonic/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.codelab.co.nz</link>
	<description>Technical Articles and News from Codelab Ltd</description>
	<lastBuildDate>Tue, 17 Jan 2012 13:10:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Decoupled Code using SubSonic</title>
		<link>http://blog.codelab.co.nz/2009/03/18/decoupled-code-using-subsonic/</link>
		<comments>http://blog.codelab.co.nz/2009/03/18/decoupled-code-using-subsonic/#comments</comments>
		<pubDate>Wed, 18 Mar 2009 10:46:39 +0000</pubDate>
		<dc:creator>Tim</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Subsonic]]></category>

		<guid isPermaLink="false">http://blog.codelab.co.nz/?p=93</guid>
		<description><![CDATA[Subsonic is fantastic when generating a bunch of classes directly from the database structure&#8230;but the issue comes when OO/Application Objects clash with relational database structures.   An idea is to use Subsonic to query the data from the database and map the data directly to a application/OO object. A really good example following the link below [...]]]></description>
			<content:encoded><![CDATA[<p>Subsonic is fantastic when generating a bunch of classes directly from the database structure&#8230;but the issue comes when OO/Application Objects clash with relational database structures.   An idea is to use Subsonic to query the data from the database and map the data directly to a application/OO object.</p>
<p>A really good example following the link below is to have a Product class that has a various number of attributes.  When you query data from the database using Subsonic you can do the following:</p>
<pre class="csharpcode">return Northwind.DB.Select(<span class="str">"ProductID"</span>, <span class="str">"ProductName"</span>, <span class="str">"UnitPrice"</span>)
                .From&lt;Northwind.Product&gt;().ExecuteTypedList&lt;Product&gt;();

//where Product is a Application Object.</pre>
<p>This attempts to map the data to ProductID, ProductName and UnitPrice attributes in the Product object.</p>
<p>Another example is to create a new application object that inherits from your subsonic generated class.<br />
This is really handy if you want to extend and add custom business logic.</p>
<pre class="csharpcode">[Serializable]
public class PersonObj : Person //Person is the SubSonic generated class
{
    public void ResetSubscription()
    {
        SubscriptionDate = DateTime.Now; //Call the SubscriptionDate database field
        ExpiryDate = DateTime.Now.AddYears(1);
        Save(); //Commit the changes back to the database
    }
}

return Select()
                .From&lt;Person&gt;().ExecuteSingle&lt;PersonObj&gt;().ResetSubscription(); //Notice the PersonObj on the end</pre>
<p><em><strong>References:</strong></em></p>
<p><a href="http://subsonicproject.com/2-1-pakala/subsonic-writing-decoupled-testable-code-with-subsonic-2-1/">http://subsonicproject.com/2-1-pakala/subsonic-writing-decoupled-testable-code-with-subsonic-2-1/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.codelab.co.nz/2009/03/18/decoupled-code-using-subsonic/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

