<?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>Schotime.net &#187; .NET</title>
	<atom:link href="http://schotime.net/blog/index.php/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://schotime.net/blog</link>
	<description>All Things .Net and Me</description>
	<lastBuildDate>Mon, 23 Apr 2012 12:16:33 +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>PetaPoco &#8211; Convention Based Fluent Mapping</title>
		<link>http://schotime.net/blog/index.php/2012/02/13/petapoco-convention-based-fluent-mapping/</link>
		<comments>http://schotime.net/blog/index.php/2012/02/13/petapoco-convention-based-fluent-mapping/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 07:33:06 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Fluent Api]]></category>
		<category><![CDATA[Mapping]]></category>
		<category><![CDATA[PetaPoco]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/?p=134</guid>
		<description><![CDATA[After using the Fluent Mapping’s I blogged about a few months ago, I started to see patterns occurring. My table names were always the pluralized type and the primary key was the Type name concatenated with “Id”. With all this repetition, I decided that conventional mappings were needed and that they should be overridable for [...]]]></description>
			<content:encoded><![CDATA[<p>After using the <a href="http://schotime.net/blog/index.php/2011/05/16/fluent-petapoco-external-mappings/" target="_blank">Fluent Mapping</a>’s I blogged about a few months ago, I started to see patterns occurring. My table names were always the pluralized type and the primary key was the Type name concatenated with “Id”. With all this repetition, I decided that conventional mappings were needed and that they should be overridable for the edge case.</p>
<p>Here is the simplest example.</p>
<div class="csharpcode">
<pre><span class="lnum"> 1: </span><span class="kwrd">protected</span> <span class="kwrd">void</span> Application_Start()</pre>
<pre><span class="lnum"> 2: </span>{</pre>
<pre><span class="lnum"> 3: </span>    FluentMappingConfiguration.Scan(x =&gt;</pre>
<pre><span class="lnum"> 4: </span>    {</pre>
<pre><span class="lnum"> 5: </span>        x.Assembly(<span class="kwrd">typeof</span> (MvcApplication).Assembly);</pre>
<pre><span class="lnum"> 6: </span>    });</pre>
<pre><span class="lnum"> 7: </span>}</pre>
</div>
<p>This just tells the FluentMapping to scan the assembly with the type MvcApplication in it and any class it finds, define a mapping so that the object will can be persisted to PetaPoco. Now by itself this is pretty pointless because by default PetaPoco already does this for you on the fly. It will use the same defaults PetaPoco currently invokes which is</p>
<ol>
<li>TableName = Type name</li>
<li>PrimaryKey = “ID”</li>
<li>PrimaryKeyAutoIncrement = on</li>
</ol>
<p>You would also not want add every type in your project either as most of them will not be used for database.</p>
<p>Ok, so we don’t want all the types, but we want to filter them by their namespace. All my DB models are in Models/Db, which has the namespace MvcApplication.Models.Db so we will use this as the filter.</p>
<div class="csharpcode">
<pre><span class="lnum"> 1: </span><span class="kwrd">protected</span> <span class="kwrd">void</span> Application_Start()</pre>
<pre><span class="lnum"> 2: </span>{</pre>
<pre><span class="lnum"> 3: </span>    FluentMappingConfiguration.Scan(x =&gt;</pre>
<pre><span class="lnum"> 4: </span>    {</pre>
<pre><span class="lnum"> 5: </span>        x.Assembly(<span class="kwrd">typeof</span> (MvcApplication).Assembly);</pre>
<pre><span class="lnum"> 6: </span>        x.IncludeTypes(type =&gt; type.Namespace == <span class="str">"MvcApplication.Models.Db"</span>);</pre>
<pre><span class="lnum"> 7: </span>    });</pre>
<pre><span class="lnum"> 8: </span>}</pre>
</div>
<p>The IncludeTypes method takes in a lambda expression with the Type as the argument and returns a bool. This method can also be used to exclude types.</p>
<p>So with all our DB models now being mapped using defaults, lets change them. Say that all our tables have the prefix “t_” on them because our DB admin likes hungarian notation. He also wants the primary key to auto increment (identity column) and the column name to end with “Id”. Ok mister Db man….you’re the boss.</p>
<div class="csharpcode">
<pre><span class="lnum"> 1: </span><span class="kwrd">protected</span> <span class="kwrd">void</span> Application_Start()</pre>
<pre><span class="lnum"> 2: </span>{</pre>
<pre><span class="lnum"> 3: </span>    FluentMappingConfiguration.Scan(x =&gt;</pre>
<pre><span class="lnum"> 4: </span>    {</pre>
<pre><span class="lnum"> 5: </span>        x.Assembly(<span class="kwrd">typeof</span>(MvcApplication).Assembly);</pre>
<pre><span class="lnum"> 6: </span>        x.IncludeTypes(type =&gt; type.Namespace == <span class="str">"MvcApplication.Models.Db"</span>);</pre>
<pre><span class="lnum"> 7: </span>        x.TablesNamed(type =&gt; <span class="str">"t_"</span> + type);</pre>
<pre><span class="lnum"> 8: </span>        x.PrimaryKeysNamed(type =&gt; type + <span class="str">"Id"</span>);</pre>
<pre><span class="lnum"> 9: </span>        x.PrimaryKeysAutoIncremented(type =&gt; <span class="kwrd">true</span>);</pre>
<pre><span class="lnum"> 10: </span>    });</pre>
<pre><span class="lnum"> 11: </span>}</pre>
</div>
<p>Too easy.</p>
<p>Next we can configure how columns are mapped. By default the column name will map to the property name, but it doesn’t have to. Our Db man says all columns should have the “d_” prefix if the column is a DateTime property, and the rest should remain the same as the property name.</p>
<div class="csharpcode">
<pre><span class="lnum"> 1: </span><span class="kwrd">protected</span> <span class="kwrd">void</span> Application_Start()</pre>
<pre><span class="lnum"> 2: </span>{</pre>
<pre><span class="lnum"> 3: </span>    FluentMappingConfiguration.Scan(x =&gt;</pre>
<pre><span class="lnum"> 4: </span>    {</pre>
<pre><span class="lnum"> 5: </span>        x.Assembly(<span class="kwrd">typeof</span> (MvcApplication).Assembly);</pre>
<pre><span class="lnum"> 6: </span>        x.IncludeTypes(type =&gt; type.Namespace == <span class="str">"MvcApplication.Models.Db"</span>);</pre>
<pre><span class="lnum"> 7: </span>        x.TablesNamed(type =&gt; <span class="str">"t_"</span> + type);</pre>
<pre><span class="lnum"> 8: </span>        x.PrimaryKeysNamed(type =&gt; type + <span class="str">"Id"</span>);</pre>
<pre><span class="lnum"> 9: </span>        x.PrimaryKeysAutoIncremented(type=&gt;<span class="kwrd">true</span>);</pre>
<pre><span class="lnum"> 10: </span></pre>
<pre><span class="lnum"> 11: </span>        x.Columns.Named(prop =&gt;</pre>
<pre>                 prop.PropertyType == <span class="kwrd">typeof</span>(DateTime) ? <span class="str">"d_"</span> + prop.Name : prop.Name);</pre>
<pre><span class="lnum"> 12: </span>    });</pre>
<pre><span class="lnum"> 13: </span>}</pre>
</div>
<p>I think you get the idea. You can also Ignore properties, set a Version columns and set a Result column.</p>
<p>There are also two extension methods that set some smart defaults. These are:</p>
<ol>
<li>Tables are the pluralized version of the Type name</li>
<li>PrimaryKeys are the Type name concatenated with “Id”</li>
<li>All complex properties (classes) are ignored</li>
</ol>
<p>These can be set simply like this.</p>
<div class="csharpcode">
<pre><span class="lnum"> 1: </span><span class="kwrd">protected</span> <span class="kwrd">void</span> Application_Start()</pre>
<pre><span class="lnum"> 2: </span>{</pre>
<pre><span class="lnum"> 3: </span>    FluentMappingConfiguration.Scan(x =&gt;</pre>
<pre><span class="lnum"> 4: </span>    {</pre>
<pre><span class="lnum"> 5: </span>        x.Assembly(<span class="kwrd">typeof</span> (MvcApplication).Assembly);</pre>
<pre><span class="lnum"> 6: </span>        x.IncludeTypes(type =&gt; type.Namespace == <span class="str">"MvcApplication.Models.Db"</span>);</pre>
<pre><span class="lnum"> 7: </span>        x.WithSmartConventions();</pre>
<pre><span class="lnum"> 8: </span>    });</pre>
<pre><span class="lnum"> 9: </span>}</pre>
</div>
<p>You can create your own extension methods as well. They are extremely easy. Check out the code for the WithSmartConventions to see how easy it is.</p>
<p>There is one last thing. Conventions are great, but if you can’t override them then they’re pretty useless, because there is always an exception to the rule. Mr Db man comes to me and says that there is one table which is used by 5 systems and does not play by our conventions we have setup. The Type name is Abc, but the table name needs to be “Abcies” not “Abcs”, and the primary key is “MyAbcId”. He also doesn’t want to map the Name column.</p>
<div class="csharpcode">
<pre><span class="lnum"> 1: </span><span class="kwrd">protected</span> <span class="kwrd">void</span> Application_Start()</pre>
<pre><span class="lnum"> 2: </span>{</pre>
<pre><span class="lnum"> 3: </span>    FluentMappingConfiguration.Scan(x =&gt;</pre>
<pre><span class="lnum"> 4: </span>    {</pre>
<pre><span class="lnum"> 5: </span>        x.Assembly(<span class="kwrd">typeof</span> (MvcApplication).Assembly);</pre>
<pre><span class="lnum"> 6: </span>        x.IncludeTypes(type =&gt; type.Namespace == <span class="str">"MvcApplication.Models.Db"</span>);</pre>
<pre><span class="lnum"> 7: </span>        x.TablesNamed(type =&gt; <span class="str">"t_"</span> + type);</pre>
<pre><span class="lnum"> 8: </span>        x.PrimaryKeysNamed(type =&gt; type + <span class="str">"Id"</span>);</pre>
<pre><span class="lnum"> 9: </span>        x.PrimaryKeysAutoIncremented(type=&gt;<span class="kwrd">true</span>);</pre>
<pre><span class="lnum"> 10: </span></pre>
<pre><span class="lnum"> 11: </span>        x.Columns.Named(prop =&gt;</pre>
<pre>                 prop.PropertyType == <span class="kwrd">typeof</span>(DateTime) ? <span class="str">"d_"</span> + prop.Name : prop.Name);</pre>
<pre><span class="lnum"> 12: </span></pre>
<pre><span class="lnum"> 13: </span>        x.OverrideMappingsWith(<span class="kwrd">new</span> MappingOverrides());</pre>
<pre><span class="lnum"> 14: </span>    });</pre>
<pre><span class="lnum"> 15: </span>}</pre>
<pre><span class="lnum"> 16: </span></pre>
<pre><span class="lnum"> 17: </span><span class="kwrd">public</span> <span class="kwrd">class</span> MappingOverrides : PetaPocoMappings</pre>
<pre><span class="lnum"> 18: </span>{</pre>
<pre><span class="lnum"> 19: </span>    <span class="kwrd">public</span> MappingOverrides()</pre>
<pre><span class="lnum"> 20: </span>    {</pre>
<pre><span class="lnum"> 21: </span>        For&lt;Abc&gt;().TableName(<span class="str">"Abcies"</span>)</pre>
<pre>                         .PrimaryKey(<span class="str">"MyAbcId"</span>)</pre>
<pre>                         .Columns(x =&gt; x.Ignore(y =&gt; y.Name));</pre>
<pre><span class="lnum"> 22: </span>    }</pre>
<pre><span class="lnum"> 23: </span>}</pre>
</div>
<p>Any mappings defined in our mapping overrides will be overlayed on top of our conventions. We covered 99% of our mappings with these conventions but still needed to manually configure one table.</p>
<p>I hope you can see how powerful this can be, especially when you’re got more than 100 tables.</p>
<p>This is currently only available on my branch, which can be found <a href="https://github.com/schotime/PetaPoco" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/schotime/PetaPoco?referer=');">https://github.com/schotime/PetaPoco</a> and downloaded <a href="https://github.com/downloads/schotime/PetaPoco/Schotime-PetaPoco-4.0.3.11.zip" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/downloads/schotime/PetaPoco/Schotime-PetaPoco-4.0.3.11.zip?referer=');">Schotime-PetaPoco-4.0.3.11.zip</a>.</p>
<p>Let me know how you get on or if you have any issues.</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2012/02/13/petapoco-convention-based-fluent-mapping/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PetaPoco &#8211; Multiple Result Sets</title>
		<link>http://schotime.net/blog/index.php/2011/11/20/petapoco-multiple-result-sets/</link>
		<comments>http://schotime.net/blog/index.php/2011/11/20/petapoco-multiple-result-sets/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 01:31:00 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[PetaPoco]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2011/11/20/petapoco-multiple-result-sets/</guid>
		<description><![CDATA[The other day I got enough time to put the ability to fetch multiple result sets into PetaPoco. Its relatively simple to use and works like this. Given these two classes with corresponding tables: public class Table1 { public string Name { get; set; } } public class Table2 { public string Col1 { get; [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I got enough time to put the ability to fetch multiple result sets into PetaPoco. Its relatively simple to use and works like this.</p>
<p>Given these two classes with corresponding tables:</p>
<div class="csharpcode">
<pre class="alt">    <span class="kwrd">public</span> <span class="kwrd">class</span> Table1</pre>
<pre>    {</pre>
<pre class="alt">        <span class="kwrd">public</span> <span class="kwrd">string</span> Name { get; set; }</pre>
<pre>    }</pre>
<pre class="alt">    <span class="kwrd">public</span> <span class="kwrd">class</span> Table2</pre>
<pre>    {</pre>
<pre class="alt">        <span class="kwrd">public</span> <span class="kwrd">string</span> Col1 { get; set; }</pre>
<pre>        <span class="kwrd">public</span> <span class="kwrd">int</span> Col2 { get; set; }</pre>
<pre class="alt">    }</pre>
</div>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Both results can be retrieved in one call to the database like so:</p>
<div class="csharpcode">
<pre class="alt">    var result = db.FetchMultiple&lt;Table1, Table2&gt;(<span class="str">&quot;select name from table1;&quot;</span> +</pre>
<pre>                                                  <span class="str">&quot;select col1,col2 from table2&quot;</span>);</pre>
<pre class="alt">    var table1list = result.Item1;  <span class="rem">//List&lt;Table1&gt;</span></pre>
<pre>    var table2list = result.Item2;  //List&lt;Table2&gt;</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>where result here is a Tuple&lt;List&lt;Table1&gt;, List&lt;Table2&gt;&gt;.</p>
<p>Here the semi-colon represents the separation of the two queries. This is the MS SQL server syntax so please check your database specific syntax to use multiple result sets.</p>
<p>If you don’t like returning a Tuple from this query you can provide your own callback to the FetchMultiple method. The callback for the above query would be of type. Func&lt;List&lt;Table1&gt;, List&lt;Table2&gt;, ReturnClass&gt;</p>
<p>The feature is currently only available in my master branch where you can find the download package here <a href="https://github.com/schotime/PetaPoco/downloads" onclick="pageTracker._trackPageview('/outgoing/github.com/schotime/PetaPoco/downloads?referer=');">https://github.com/schotime/PetaPoco/downloads</a> or directly <a title="https://github.com/downloads/schotime/PetaPoco/Schotime-PetaPoco-4.0.3.5.zip" href="https://github.com/downloads/schotime/PetaPoco/Schotime-PetaPoco-4.0.3.5.zip" onclick="pageTracker._trackPageview('/outgoing/github.com/downloads/schotime/PetaPoco/Schotime-PetaPoco-4.0.3.5.zip?referer=');">https://github.com/downloads/schotime/PetaPoco/Schotime-PetaPoco-4.0.3.5.zip</a>.</p>
<p>Hope you find it useful.
  </p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2011/11/20/petapoco-multiple-result-sets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PetaPoco &#8211; One To Many and Many To One</title>
		<link>http://schotime.net/blog/index.php/2011/08/21/petapoco-one-to-many-and-many-to-one/</link>
		<comments>http://schotime.net/blog/index.php/2011/08/21/petapoco-one-to-many-and-many-to-one/#comments</comments>
		<pubDate>Sat, 20 Aug 2011 15:04:36 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Many-to-One]]></category>
		<category><![CDATA[One-to-Many]]></category>
		<category><![CDATA[PetaPoco]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2011/08/21/petapoco-one-to-many-and-many-to-one/</guid>
		<description><![CDATA[PetaPoco is a great way to map results from a database. Usually these are flat objects, however sometimes its useful to map many-to-one/one-to-many relationship directly into a viewmodel or complex object. This feature has been possible in PetaPoco since version 4 as shown in the blog post by Brad, (http://www.toptensoftware.com/Articles/115/PetaPoco-Mapping-One-to-Many-and-Many-to-One-Relationships) however, custom mapping needed to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.toptensoftware.com/petapoco/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.toptensoftware.com/petapoco/?referer=');">PetaPoco</a> is a great way to map results from a database. Usually these are flat objects, however sometimes its useful to map many-to-one/one-to-many relationship directly into a viewmodel or complex object. </p>
<p>This feature has been possible in PetaPoco since version 4 as shown in the blog post by Brad, (<a href="http://www.toptensoftware.com/Articles/115/PetaPoco-Mapping-One-to-Many-and-Many-to-One-Relationships" onclick="pageTracker._trackPageview('/outgoing/www.toptensoftware.com/Articles/115/PetaPoco-Mapping-One-to-Many-and-Many-to-One-Relationships?referer=');">http://www.toptensoftware.com/Articles/115/PetaPoco-Mapping-One-to-Many-and-Many-to-One-Relationships</a>) however, custom mapping needed to be created each type. Therefore I decided to have a crack at a more generic way of mapping these.</p>
<p>You can grab it now and give it a try. Its available on NuGet under <a href="http://nuget.org/List/Packages/PetaPoco.RelationExtensions" target="_blank" onclick="pageTracker._trackPageview('/outgoing/nuget.org/List/Packages/PetaPoco.RelationExtensions?referer=');">PetaPoco.RelationExtensions</a>.</p>
<p>The extensions add two new methods to the Database class. They come with a variety of overloads for a multitude of generic arguments.</p>
<ol>
<li>FetchOneToMany&lt;&gt;</li>
<li>FetchManyToOne&lt;&gt;</li>
</ol>
<p>This is how it works:</p>
<pre class="csharpcode">var results1 = db.FetchOneToMany&lt;BudgetPeriod, Expense&gt;(x =&gt; x.BudgetPeriodId,
        <span class="str">&quot;select b.*, e.* from budgetperiods b &quot;</span> +
        <span class="str">&quot;   inner join expenses e on b.budgetperiodid = e.budgetperiodid&quot;</span>);

var results2 = db.FetchManyToOne&lt;Expense, BudgetPeriod, BudgetPeriod&gt;(x =&gt; x.ExpenseId,
        <span class="str">&quot;select e.*, b.*, b2.* from budgetperiods b &quot;</span> +
        <span class="str">&quot;   inner join expenses e on b.budgetperiodid = e.budgetperiodid &quot;</span> +
        <span class="str">&quot;   inner join budgetperiods b2 on e.budgetperiodid = b2.budgetperiodid &quot;</span>);</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>results1 will return a List&lt;BudgetPeriod&gt;<br />
  <br />results2 will return a List&lt;Expense&gt;</p>
<p>There are some key things to remember when using these.</p>
<ol>
<li>It is critical that the columns that you want to map into the class are in the same order you specify the generic arguments as seen in the results2 example above. eg. Expense, BP, BP –&gt; e.*, b.*, b2.*</li>
<li>The first parameter is a lamda which should refer to the primary key of the first T argument. </li>
</ol>
<p>Currently you can only have 1 one-to-many relation mapped and up to 3 many-to-one relations mapped in one go.</p>
<p>Enjoy<br />
  <br />Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2011/08/21/petapoco-one-to-many-and-many-to-one/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PetaPoco.Glimpse &#8211; NuGet Package</title>
		<link>http://schotime.net/blog/index.php/2011/05/31/petapoco-glimpse-nuget-package/</link>
		<comments>http://schotime.net/blog/index.php/2011/05/31/petapoco-glimpse-nuget-package/#comments</comments>
		<pubDate>Tue, 31 May 2011 13:41:53 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Glimpse]]></category>
		<category><![CDATA[peformance]]></category>
		<category><![CDATA[PetaPoco]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2011/05/31/petapoco-glimpse-nuget-package/</guid>
		<description><![CDATA[A couple of weeks ago I showed how we can use the awesome Glimpse project with PetaPoco to show all the SQL’s processed in the current request. The problem was there was a few things that needed to make it into both PetaPoco and Glimpse to support this. The PetaPoco changes were in place as [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of weeks ago I <a href="http://schotime.net/blog/index.php/2011/05/09/a-glimpse-into-petapoco/" target="_blank">showed</a> how we can use the awesome <a href="http://getglimpse.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/getglimpse.com?referer=');">Glimpse</a> project with <a href="http://www.toptensoftware.com/petapoco/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.toptensoftware.com/petapoco/?referer=');">PetaPoco</a> to show all the SQL’s processed in the current request. The problem was there was a few things that needed to make it into both PetaPoco and Glimpse to support this. The PetaPoco changes were in place as of v3.0.2 (thanks Brad) and a bug fix I submitted to the Glimpse team was just merged into (thanks Nik and Anthony) v0.82. </p>
<p>Therefore I give you PetaPoco.Glimpse. A simple NuGet package that brings it all together. Firstly create a new Asp.Net MVC 3 Project. Right click on References and select “Add Library Package Reference”. The following dialog will appear. Search for petapoco in the top right corner. It will look similar to below. Select PetaPoco.Glimpse and select Install. This will install PetaPoco.Core as well as Glimpse.</p>
<p><a href="http://schotime.net/blog/wp-content/uploads/2011/05/PetaPoco.Glimpse.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="PetaPoco.Glimpse" border="0" alt="PetaPoco.Glimpse" src="http://schotime.net/blog/wp-content/uploads/2011/05/PetaPoco.Glimpse_thumb.jpg" width="624" height="371" /></a> </p>
<p>Once it downloads the package and installs it you are almost ready to go. Here is the simplest way to get under way, however usually you would create your own DB class which inherits DatabaseWithProfiling.</p>
<pre class="csharpcode"><span class="rem">// &quot;Peta&quot; is the name of my connection string</span>
var db = <span class="kwrd">new</span> DatabaseWithProfiling(<span class="str">&quot;Peta&quot;</span>);
var data = db.Fetch&lt;dynamic&gt;(<span class="str">&quot;select id, name from users where id = @0&quot;</span>, 1);</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Placed the above code into the HomeController and run the application. Note: You will also have to turn Glimpse On by heading to /Glimpse/Config. Once done, head back to the default url and you see an Eye icon in the bottom right corner. Clicking this will result it the following output.</p>
<p><a href="http://schotime.net/blog/wp-content/uploads/2011/05/PetaPoco.Glimpse1.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="PetaPoco.Glimpse1" border="0" alt="PetaPoco.Glimpse1" src="http://schotime.net/blog/wp-content/uploads/2011/05/PetaPoco.Glimpse1_thumb.jpg" width="630" height="148" /></a> </p>
<p>As you can see, the PetaPoco tab shows you all the details about the SQL’s that were run in the order they were run. </p>
<p>There are a few caveats on the SQL’s showing up.<br />
  <br />1. Debug must be on. </p>
<p>2. You can force the logging by setting –&gt; db.ForceLogging = true;</p>
<p>Please let me know if you have any queries and enjoy. </p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2011/05/31/petapoco-glimpse-nuget-package/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Fluent PetaPoco &#8211; External Mappings</title>
		<link>http://schotime.net/blog/index.php/2011/05/16/fluent-petapoco-external-mappings/</link>
		<comments>http://schotime.net/blog/index.php/2011/05/16/fluent-petapoco-external-mappings/#comments</comments>
		<pubDate>Mon, 16 May 2011 13:07:04 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Fluent Api]]></category>
		<category><![CDATA[PetaPoco]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2011/05/16/fluent-petapoco-external-mappings/</guid>
		<description><![CDATA[Update 20/Nov/2011: This has been now added to my master branch and is available here for download as of 4.0.3.5. https://github.com/schotime/PetaPoco/downloads The other day I set out to build another way to configure the mappings for PetaPoco. Here is how you currently configure a mapping using attributes. [TableName(&#34;AttribPocos&#34;)] [PrimaryKey(&#34;Id&#34;)] public class attribpoco { public int [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update 20/Nov/2011: </strong>This has been now added to my master branch and is available here for download as of 4.0.3.5. <a href="https://github.com/schotime/PetaPoco/downloads" onclick="pageTracker._trackPageview('/outgoing/github.com/schotime/PetaPoco/downloads?referer=');">https://github.com/schotime/PetaPoco/downloads</a></p>
<p>The other day I set out to build another way to configure the mappings for PetaPoco. Here is how you currently configure a mapping using attributes.   </p>
<pre class="csharpcode">    [TableName(<span class="str">&quot;AttribPocos&quot;</span>)]
    [PrimaryKey(<span class="str">&quot;Id&quot;</span>)]
    <span class="kwrd">public</span> <span class="kwrd">class</span> attribpoco
    {
        <span class="kwrd">public</span> <span class="kwrd">int</span> Id { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">string</span> Name { get; set; }
        <span class="kwrd">public</span> <span class="kwrd">string</span> Result { get; set; }

        [Ignore]
        <span class="kwrd">public</span> <span class="kwrd">int</span> IgnoreColumn { get; set; }
    }</pre>
<p>
  <br /><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->This is pretty easy and requires only a couple of attributes. After you do a few of these, sometimes I wish I could set all the mappings in one place, so here is the same mappings but with my new configuration. Method 1.</p>
<p></p>
<pre class="csharpcode">    <span class="kwrd">public</span> <span class="kwrd">class</span> MyMappings : PetaPocoMappings
    {
        <span class="kwrd">public</span> MyMappings()
        {
            For&lt;attribpoco&gt;()
                .TableName(<span class="str">&quot;AttribPocos&quot;</span>)
                .PrimaryKey(x =&gt; x.Id)
                .Columns(x =&gt;
                             {
                                 x.Ignore(y =&gt; y.IgnoreColumn);
                             });
        }
    }</pre>
<p>
  <br /><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->So you can define multiple mappings here with new For&lt;&gt; statements. If you want to be more explicit and have one mapping class per mapping you can do the following. Method 2.</p>
<p></p>
<pre class="csharpcode">    <span class="kwrd">public</span> <span class="kwrd">class</span> AttribPocoMap : PetaPocoMap&lt;attribpoco&gt;
    {
        <span class="kwrd">public</span> AttribPocoMap()
        {
            TableName(<span class="str">&quot;AttribPocos&quot;</span>);
            PrimaryKey(x =&gt; x.Id);
            Columns(x =&gt;
                        {
                            x.Ignore(y =&gt; y.IgnoreColumn);
                        });
        }
    }</pre>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->Both ways of mapping have the same API, so they can be interchanged, however when hooking the mappings into PetaPoco, things differ a little.</p>
<p>You need to configure the mappings just once in your application so a good place to do that in a web application is the Application_Start() method in the global.asax.cs. Here is how you do this for the first method of mapping configuration.</p>
<pre>PetaPoco.FluentMappings.Configuration.Configure(new MyMappings());</pre>
<p>For method 2 you have to be a little more explicit at the moment. For each mapping you need to include it as a parameter to Configure.</p>
<p></p>
<pre class="csharpcode">PetaPoco.FluentMappings.Configuration.Configure(<span class="kwrd">new</span> AttribPocoMap(),…);</pre>
<p><!-- .csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } -->Also, just because you have used the fluent mappings for one class, you can use the attribute mapping style at any time as it will automatically default back to the attribute mappings if you don’t have a fluent mapping configured. You also don’t have to define all the columns. By default all columns are mapped unless you are using explicit mappings or you have used the Ignore or Result column like above.</p>
<p>Currently all features supported by attributes in my branch are supported in the fluent mappings. eg. Sequences, Explicit Columns, Composite Keys, Versioning, Ignore Columns and Result Columns.</p>
<p>If you would like to give it a try you can download the my PetaPoco branch here:</p>
<p><a href="https://github.com/schotime/PetaPoco/downloads" onclick="pageTracker._trackPageview('/outgoing/github.com/schotime/PetaPoco/downloads?referer=');">https://github.com/schotime/PetaPoco/downloads</a></p>
<p>Let me know what you think.</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2011/05/16/fluent-petapoco-external-mappings/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Creating Your Own Glimpse Plugin</title>
		<link>http://schotime.net/blog/index.php/2011/05/10/creating-your-own-glimpse-plugin/</link>
		<comments>http://schotime.net/blog/index.php/2011/05/10/creating-your-own-glimpse-plugin/#comments</comments>
		<pubDate>Tue, 10 May 2011 11:02:00 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Glimpse]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2011/05/10/creating-your-own-glimpse-plugin/</guid>
		<description><![CDATA[Last weekend I created a Glimpse plugin for PetaPoco. It was surprisingly easy. In this post I’ll show you how to create your own. Please note as Glimpse is still in Beta, this example may change. but I will endeavour to update the post when and if the interface changes. This plugin is based on [...]]]></description>
			<content:encoded><![CDATA[<p>Last weekend I created a <a href="http://getglimpse.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/getglimpse.com?referer=');">Glimpse</a> plugin for <a href="http://www.toptensoftware.com/petapoco/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.toptensoftware.com/petapoco/?referer=');">PetaPoco</a>. It was surprisingly easy. In this post I’ll show you how to create your own. </p>
<p><strong>Please note as Glimpse is still in Beta, this example may change. but I will endeavour to update the post when and if the interface changes. This plugin is based on Glimpse 0.81.</strong></p>
<p>Here is the complete code for our first plugin.</p>
<pre class="csharpcode">    [GlimpsePlugin(ShouldSetupInInit=true)]
    <span class="kwrd">public</span> <span class="kwrd">class</span> MyFirstGlimpsePlugin : IGlimpsePlugin
    {
        <span class="kwrd">private</span> <span class="kwrd">int</span> MaxValue;

        <span class="kwrd">public</span> <span class="kwrd">object</span> GetData(HttpApplication application)
        {
            <span class="rem">// Return the data you want to display on your tab</span>
            var data = <span class="kwrd">new</span> List&lt;<span class="kwrd">object</span>[]&gt; {<span class="kwrd">new</span>[]{ <span class="str">&quot;Column1&quot;</span>, <span class="str">&quot;Column2&quot;</span>, <span class="str">&quot;Column3&quot;</span> }};

            <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; MaxValue; i++)
            {
                <span class="rem">// Usually get your data from application.Context.Items</span>
                data.Add(<span class="kwrd">new</span> <span class="kwrd">object</span>[] {<span class="str">&quot;Data &quot;</span> + i, 10*i, DateTime.Now.AddHours(i)});
            }

            <span class="kwrd">return</span> data;
        }

        <span class="kwrd">public</span> <span class="kwrd">void</span> SetupInit(HttpApplication application)
        {
            <span class="rem">// Perform an initialisation that needs to be done.</span>
            <span class="rem">// Run once at startup</span>
            MaxValue = 5;
        }

        <span class="kwrd">public</span> <span class="kwrd">string</span> Name
        {
            get { <span class="kwrd">return</span> <span class="str">&quot;MyFirstPlugin&quot;</span>; }
        }
    }</pre>
<p>There are three parts.<br />
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
</p>
<p>1. The Name get accessor: This is the name of the tab.<br />
  <br />2. SetupInit method: This method will run once when the Plugin is loaded. Perform any initialisation code here. </p>
<p>3. GetData method: This is where the action happens. All data returned from here will be serialized into JSON and sent to the client to be rendered by the Glimpse client side framework. How it is exactly rendered depends on whether you return arrays or objects or arrays of objects etc. Initial details for this can be found on the <a href="http://getglimpse.com/protocol" target="_blank" onclick="pageTracker._trackPageview('/outgoing/getglimpse.com/protocol?referer=');">Protocol page</a>. Usually you would put the data you need to display in the HttpContext.Items dictionary in part of your application. You can then pull the data out using the application variable provided to you in the GetData method.</p>
<p>For example<br />
  <br />-&gt; data goes in:&#160; HttpContext.Current.Items[“test”] = “Some data”; </p>
<p>-&gt; data comes out:&#160; var testdata = application.Context.Items[“test”]</p>
<p>The following is rendered by Glimpse.</p>
<p><a href="http://schotime.net/blog/wp-content/uploads/2011/05/GlimpsefirstPlugin.jpg" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Glimpse-firstPlugin" border="0" alt="Glimpse-firstPlugin" src="http://schotime.net/blog/wp-content/uploads/2011/05/GlimpsefirstPlugin_thumb.jpg" width="611" height="342" /></a> </p>
<p>As you will see, it doesn’t matter what data you put in what column as Glimpse will do its best to render the data in the most approriate way. If I change the GetData method to be:</p>
<pre class="csharpcode">        <span class="kwrd">public</span> <span class="kwrd">object</span> GetData(HttpApplication application)
        {
            <span class="rem">// Return the data you want to display on your tab</span>
            var data = <span class="kwrd">new</span> List&lt;<span class="kwrd">object</span>[]&gt; {<span class="kwrd">new</span>[]{ <span class="str">&quot;Column1&quot;</span>, <span class="str">&quot;Column2&quot;</span>, <span class="str">&quot;Column3&quot;</span> }};

            <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; MaxValue; i++)
            {
                <span class="rem">// Usually get your data from application.Context.Items</span>
                data.Add(<span class="kwrd">new</span> <span class="kwrd">object</span>[] {<span class="str">&quot;Data &quot;</span> + i, 10*i, DateTime.Now.AddHours(i)});
            }

            var nestedData = <span class="kwrd">new</span> Dictionary&lt;<span class="kwrd">string</span>, <span class="kwrd">object</span>&gt;
                                 {
                                     {<span class="str">&quot;NestKey1&quot;</span>, <span class="str">&quot;NestedValue&quot;</span>},
                                     {<span class="str">&quot;NestKey2&quot;</span>, 2 },
                                     {<span class="str">&quot;NestKey3&quot;</span>, DateTime.Now }
                                 };

            data.Add(<span class="kwrd">new</span> <span class="kwrd">object</span>[] { <span class="str">&quot;Data Nested&quot;</span>, 60, nestedData });

            <span class="kwrd">return</span> data;
        }</pre>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>the following is rendered by Glimpse.</p>
<p><a href="http://schotime.net/blog/wp-content/uploads/2011/05/GlimpsefirstPlugin2.jpg" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Glimpse-firstPlugin2" border="0" alt="Glimpse-firstPlugin2" src="http://schotime.net/blog/wp-content/uploads/2011/05/GlimpsefirstPlugin2_thumb.jpg" width="618" height="333" /></a> </p>
<p>As you can see the Glimpse team have made it super easy to create your own plugin. It literally takes minutes.</p>
<p>Enjoy<br />
  <br />Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2011/05/10/creating-your-own-glimpse-plugin/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>A Glimpse into PetaPoco</title>
		<link>http://schotime.net/blog/index.php/2011/05/09/a-glimpse-into-petapoco/</link>
		<comments>http://schotime.net/blog/index.php/2011/05/09/a-glimpse-into-petapoco/#comments</comments>
		<pubDate>Mon, 09 May 2011 11:51:49 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Glimpse]]></category>
		<category><![CDATA[PetaPoco]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2011/05/09/a-glimpse-into-petapoco/</guid>
		<description><![CDATA[Last week I blogged about upcoming performance statistics that enable you to see all the Sql’s that were executed by PetaPoco in the current request. It was also just over a week ago that I learned about Glimpse from this Mix video by Scott Hanselman. And wow what an impact. Anthony van der Hoorn (@anthony_vdh) [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I <a href="http://schotime.net/blog/index.php/2011/05/03/petapoco-performance-statistics/" target="_blank">blogged</a> about upcoming performance statistics that enable you to see all the Sql’s that were executed by <a href="http://www.toptensoftware.com/petapoco/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.toptensoftware.com/petapoco/?referer=');">PetaPoco</a> in the current request.</p>
<p>It was also just over a week ago that I learned about <a href="http://getglimpse.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/getglimpse.com?referer=');">Glimpse</a> from this <a href="http://channel9.msdn.com/Events/MIX/MIX11/FRM02" target="_blank" onclick="pageTracker._trackPageview('/outgoing/channel9.msdn.com/Events/MIX/MIX11/FRM02?referer=');">Mix video</a> by <a href="http://hanselman.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/hanselman.com?referer=');">Scott Hanselman</a>. And wow what an impact. <strong>Anthony van der Hoorn</strong> (<a href="http://twitter.com/anthony_vdh" onclick="pageTracker._trackPageview('/outgoing/twitter.com/anthony_vdh?referer=');">@anthony_vdh</a>) and <strong>Nik Molnar</strong> (<a href="http://twitter.com/nikmd23" onclick="pageTracker._trackPageview('/outgoing/twitter.com/nikmd23?referer=');">@nikmd23</a>) had created a wonderful diagnostics system for Asp.net MVC. Firebug for the server if you will.</p>
<p>I then wondered if I could somehow plug PetaPoco diagnostics into the display for Glimpse and it was unbelievably easy. Implementing a single interface was all it took. Less than 50 lines of code in total to produce the following results. I will show you how to create your own tab in a future post. <strong>Update</strong>: <a href="http://schotime.net/blog/index.php/2011/05/10/creating-your-own-glimpse-plugin/" target="_blank">Creating Your Own Glimpse Plugin</a></p>
<p><a href="http://schotime.net/blog/wp-content/uploads/2011/05/petapoco_glimpse2.jpg"><img style="display: inline; margin-left: 0px; margin-right: 0px; border-width: 0px;" title="petapoco_glimpse2" src="http://schotime.net/blog/wp-content/uploads/2011/05/petapoco_glimpse2_thumb.jpg" border="0" alt="petapoco_glimpse2" width="317" height="182" align="left" /></a></p>
<p>This gives a pretty clear display of exactly what queries were performed during the current request.</p>
<p>Another powerful feature of Glimpse is that it saves the last n (default 5) requests so it is indeed possible to get access to the Sql’s performed when posting data back to the server.</p>
<p>It really is a credit to the guys for a wonderful project which still hasn’t reached a V1.</p>
<p>My aim is to have both the integration to Glimpse and html source statistics available within the week but it all depends on whether the integration points make it into the main branch before hand.</p>
<p><strong>Update</strong> (01/06/2011): This is now available as a package from NuGet called PetaPoco.Glimpse.</p>
<p>Until then, check out <a href="http://getglimpse.com" target="_blank" onclick="pageTracker._trackPageview('/outgoing/getglimpse.com?referer=');">Glimpse</a> (on NuGet as well) and support it by providing valuable feedback to the team.</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2011/05/09/a-glimpse-into-petapoco/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PetaPoco &#8211; Why I&#8217;m Using A Micro-ORM</title>
		<link>http://schotime.net/blog/index.php/2011/05/04/petapoco-why-im-using-a-micro-orm/</link>
		<comments>http://schotime.net/blog/index.php/2011/05/04/petapoco-why-im-using-a-micro-orm/#comments</comments>
		<pubDate>Wed, 04 May 2011 12:30:03 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Micro-ORM]]></category>
		<category><![CDATA[PetaPoco]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2011/05/04/petapoco-why-im-using-a-micro-orm/</guid>
		<description><![CDATA[As I mentioned a few posts ago, in the last couple of years I moved away from writing native SQL to a full blown ORM and back again. Well not all the way back. Here is where PetaPoco comes in. I had been using my own SQL to Object mapper for a while before I [...]]]></description>
			<content:encoded><![CDATA[<p>As I <a href="http://schotime.net/blog/index.php/2011/05/01/getting-back-in-touch-with-sql/" target="_blank">mentioned</a> a few posts ago, in the last couple of years I moved away from writing native SQL to a full blown ORM and back again. Well not all the way back. Here is where <a href="http://www.toptensoftware.com/petapoco/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.toptensoftware.com/petapoco/?referer=');">PetaPoco</a> comes in.</p>
<p>I had been using my own SQL to Object mapper for a while before I stumbled over PetaPoco, and it had very similar ideas to mine. It has gone one step further though, with nice support for paging, inserts, updates, deletes and multiple database support. </p>
<p>Since forking the <a href="https://github.com/toptensoftware/petapoco" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/toptensoftware/petapoco?referer=');">repository</a> at Github, I have implemented and suggested many changes that have made it back (thanks to Brad) into the main repository. Some of these include support for <a href="http://www.toptensoftware.com/Articles/103/PetaPoco-Oracle-Support-and-more" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.toptensoftware.com/Articles/103/PetaPoco-Oracle-Support-and-more?referer=');">Oracle</a> (including sequences for PK), DB field to Object field name <a href="http://www.toptensoftware.com/Articles/92/PetaPoco-Custom-mapping-with-the-Mapper-interface" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.toptensoftware.com/Articles/92/PetaPoco-Custom-mapping-with-the-Mapper-interface?referer=');">conventions</a> (and the ability to customize these per project). </p>
<p>So why have I come the full circle on this. </p>
<ol>
<li>Well firstly, SQL is a great query language for RDMS databases. It is very very powerful and I don’t think that it is all that difficult to learn. </li>
<li>Just give me my data. I just want to create a sql query and map it to my object so I can use it. I don’t want to have explicit mapping files/code.</li>
<li>The pain is just not worth it IMO. Why should I have to spend excess time trying to figure out if this query is going to produce a select n+1 or that I have to traverse 4 deep to get a piece of data?</li>
<li>One file. Its not 1 DLL or 10 DLLs. Its one cs file that you just drop in to your project. It doesn’t get much simpler than that.</li>
<li>Performance. I just don’t have to worry that I’m losing any performance between the database and my object. If there are performance issues, its either the query or the business logic.</li>
</ol>
<p>And those are just some of the reasons.    </p>
<p>To see how to use the basic features of PetaPoco, please visit the <a href="http://www.toptensoftware.com/petapoco/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.toptensoftware.com/petapoco/?referer=');">PetaPoco home page</a>.</p>
<p>At the moment my <a href="http://github.com/schotime/petapoco" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/schotime/petapoco?referer=');">fork</a> contains a few extra features that are not currently in Brad’s repository. These include multiple primary key support for legacy database, concurrency using a version column, an OnCommandExecuted extension point and a IDatabase interface. I also have the PetaPoco.cs file set to “No Dynamic” at the moment as I’m using it with .NET 3.5. To enable the dynamic object mapping support, comment out the follow line (currently line 11).</p>
<pre class="csharpcode"><span class="preproc">#define</span> PETAPOCO_NO_DYNAMIC</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>In future blog posts I intend to go through a few examples of how I have using it and how the extension points enable you to do some pretty interesting things.</p>
<p>Now I know this won’t be for everyone but unless forced, I won’t be going back to a full blown ORM. </p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2011/05/04/petapoco-why-im-using-a-micro-orm/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>PetaPoco Performance Statistics</title>
		<link>http://schotime.net/blog/index.php/2011/05/03/petapoco-performance-statistics/</link>
		<comments>http://schotime.net/blog/index.php/2011/05/03/petapoco-performance-statistics/#comments</comments>
		<pubDate>Tue, 03 May 2011 13:46:09 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[PetaPoco]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2011/05/03/petapoco-performance-statistics/</guid>
		<description><![CDATA[The other day Sam from stackoverflow blogged about a slow page caused by a combination of problems resulting in them using Dapper to map native SQL to the objects resulting in a nice performance improvement. I liked how he made the queries executed for the current request display in html comments in the html source, [...]]]></description>
			<content:encoded><![CDATA[<p>The other day <a href="http://samsaffron.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/samsaffron.com/?referer=');">Sam</a> from stackoverflow <a href="http://samsaffron.com/archive/2011/05/02/A+day+in+the+life+of+a+slow+page+at+Stack+Overflow" target="_blank" onclick="pageTracker._trackPageview('/outgoing/samsaffron.com/archive/2011/05/02/A+day+in+the+life+of+a+slow+page+at+Stack+Overflow?referer=');">blogged</a> about a slow page caused by a combination of problems resulting in them using <a href="http://code.google.com/p/dapper-dot-net/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/dapper-dot-net/?referer=');">Dapper</a> to map native SQL to the objects resulting in a nice performance improvement.</p>
<p>I liked how he made the queries executed for the current request display in html comments in the html source, so I thought I would see if I could implement the same thing with <a href="http://www.toptensoftware.com/petapoco/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.toptensoftware.com/petapoco/?referer=');">PetaPoco</a>. I intend to go through how I implemented the following in future posts (after I go through some basics), but for the moment I’ll give you a quick screen grab of what it looks like. Thanks goes to Sam for providing the inspiration.</p>
<p><a href="http://schotime.net/blog/wp-content/uploads/2011/05/petapoco_db_stats.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="petapoco_db_stats" border="0" alt="petapoco_db_stats" src="http://schotime.net/blog/wp-content/uploads/2011/05/petapoco_db_stats_thumb.jpg" width="948" height="586" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2011/05/03/petapoco-performance-statistics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Increasing Event Binding Performance using Jquery Delegate</title>
		<link>http://schotime.net/blog/index.php/2011/05/02/increasing-event-binding-performance-using-jquery-delegate/</link>
		<comments>http://schotime.net/blog/index.php/2011/05/02/increasing-event-binding-performance-using-jquery-delegate/#comments</comments>
		<pubDate>Mon, 02 May 2011 13:57:32 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[peformance]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/index.php/2011/05/02/increasing-event-binding-performance-using-jquery-delegate/</guid>
		<description><![CDATA[Today I was presented with a problem when binding click events to action icons. You know the scenario; you have a table with a list of data and one of the columns has icons/links like “edit”, “new”, “view”, “delete” etc. This is how I’m using the jQuery to bind the click event to the links [...]]]></description>
			<content:encoded><![CDATA[<p>Today I was presented with a problem when binding click events to action icons. You know the scenario; you have a table with a list of data and one of the columns has icons/links like “edit”, “new”, “view”, “delete” etc. This is how I’m using the jQuery to bind the click event to the links like so.</p>
<pre class="csharpcode">$(<span class="str">&quot;a.action&quot;</span>).click(<span class="kwrd">function</span>() {
    <span class="rem">// perform tasks</span>
});</pre>
<p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>This worked great, however when the list grew to 50 or more items, IE (yes i know) started complaining that the script is running too long. Now at the moment I have 7 actions multiplied by 50 items in the list which means it was looping 350 times. It shouldn’t be that bad but before IE9 JS performance is woeful. </p>
<p>To fix this issue, I needed to reduce the amount of event bindings. This is where <a href="http://api.jquery.com/delegate/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/api.jquery.com/delegate/?referer=');">jQuery.delegate()</a> comes in. The syntax is a little different but its pretty easy to understand.</p>
<pre class="csharpcode">$(<span class="str">&quot;#listtable&quot;</span>).<span class="kwrd">delegate</span>(<span class="str">&quot;a.action&quot;</span>, <span class="str">&quot;click&quot;</span>, <span class="kwrd">function</span>() {
    <span class="rem">// perform tasks</span>
});</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>The selector in this case is the table where the links are contained within (children). The first parameter is the filter for the link that needs to be clicked. The second parameter is the event name. Custom events can be used here. And the third parameter is the callback function. So its pretty similar, however instead of creating 50 events, one for each row, I’m binding the event to the surrounding table element and then using the fact that the events bubble up through parent elements to catch the appropriate event.</p>
<p>IE happy, Adam happy!
  </p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2011/05/02/increasing-event-binding-performance-using-jquery-delegate/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

