<?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</title>
	<atom:link href="http://schotime.net/blog/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://schotime.net/blog</link>
	<description>All Things .Net and Me</description>
	<lastBuildDate>Sat, 12 Jul 2014 13:00:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Html Conventions in ASP.net MVC</title>
		<link>http://schotime.net/blog/index.php/2014/07/12/html-conventions-in-asp-net-mvc-2/</link>
		<comments>http://schotime.net/blog/index.php/2014/07/12/html-conventions-in-asp-net-mvc-2/#comments</comments>
		<pubDate>Sat, 12 Jul 2014 13:00:07 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[SchoStack]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/?p=175</guid>
		<description><![CDATA[Just today, Jimmy wrote a great post on using HTML conventions in ASP.net MVC using FubuMvc’s core HTML conventions. Go ahead a read it. I’ll wait here. The problem with this is that it heavily relies on StructureMap (FWIW I love SM, but its overkill here), and doesn’t quite fit into the way ASP.net MVC]]></description>
				<content:encoded><![CDATA[<p>Just today, <a href="http://lostechies.com/jimmybogard/2014/07/11/conventional-html-in-asp-net-mvc-adopting-fubu-conventions/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/lostechies.com/jimmybogard/2014/07/11/conventional-html-in-asp-net-mvc-adopting-fubu-conventions/?referer=');">Jimmy</a> wrote a great post on using HTML conventions in ASP.net MVC using FubuMvc’s core HTML conventions. Go ahead a read it. I’ll wait here.</p>
<p>The problem with this is that it heavily relies on StructureMap (FWIW I love SM, but its overkill here), and doesn’t quite fit into the way ASP.net MVC does things. It also requires a lot of setup. I found this out almost 2 years ago now, and so <a href="http://www.nuget.org/packages/schostack.web" target="_blank" onclick="pageTracker._trackPageview('/outgoing/www.nuget.org/packages/schostack.web?referer=');">SchoStack.Web</a> was born. Over the coming posts I will go through what’s included in the library, but here is how you quickly get up and running with the default conventions (these represent the defaults that render lists, dropdowns, checkbox&#8217;s which are all ASP.net MVC compliant).</p>
<ol>
<li>Create new mvc project. </li>
<li>install-package schostack.web </li>
<li>Replace System.Web.Html namespaces in Views/web.config with the following      <br />&lt;add namespace=&quot;SchoStack.Web.Html&quot; /&gt;       <br />&lt;add namespace=&quot;SchoStack.Web.Html.Form&quot; /&gt; </li>
<li>In Application_Start add:      <br />HtmlConventionFactory.Add(new DefaultHtmlConventions());       <br />HtmlConventionFactory.Add(new DataAnnotationHtmlConventions());       <br />HtmlConventionFactory.Add(new DataAnnotationValidationHtmlConventions()); </li>
<li>Thats it. </li>
</ol>
<p>The following are the three main helpers used to generate all HTML based on your conventions.</p>
<p>@Html.Input(x=&gt;x.Name)    <br />@Html.Display(x=&gt;x.Name)     <br />@Html.Label(x=&gt;x.Name)</p>
<p>All the usual MVC helpers are available as well like ValidationSummary and ValidationMessage. </p>
<p>I’ll try to cover the following things in upcoming posts, but if you have any questions or issues you can ask/raise them on <a href="http://github.com/schotime/schostack.web" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/schotime/schostack.web?referer=');">github</a>. </p>
<p>1. Creating your own conventions    <br />2. Closer look at out of the box conventions     <br />3. Validation (Server and Client validation using either FluentValidation and Data Annotations driven off the input model, not the viewmodel)     <br />4. Foreach Loop Helpers     <br />5. Url Generation and Routing     </p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2014/07/12/html-conventions-in-asp-net-mvc-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NPoco 2.0</title>
		<link>http://schotime.net/blog/index.php/2013/04/20/npoco-2-0/</link>
		<comments>http://schotime.net/blog/index.php/2013/04/20/npoco-2-0/#comments</comments>
		<pubDate>Sat, 20 Apr 2013 11:21:12 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[NPoco]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/?p=164</guid>
		<description><![CDATA[Today I finally published NPoco 2.0. It has been 6 months in the making and 13 pre-release versions. Thankyou to all who have raised bugs and used it in anger. Most of the documentation has been published to the github wiki, however if you find something that is missing please let me know and I]]></description>
				<content:encoded><![CDATA[<p>Today I finally published <a href="http://nuget.org/packages/NPoco" target="_blank" onclick="pageTracker._trackPageview('/outgoing/nuget.org/packages/NPoco?referer=');">NPoco 2.0</a>. It has been 6 months in the making and 13 pre-release versions. Thankyou to all who have raised bugs and used it in anger.</p>
<p>Most of the documentation has been published to the github <a href="https://github.com/schotime/NPoco/wiki" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/schotime/NPoco/wiki?referer=');">wiki</a>, however if you find something that is missing please let me know and I will endeavour to fix that.</p>
<p>There should be very limited breaking changes in 2.0, but if you have always just passed the connection string to the Database object then nothing will probably change. You can also specify the database type now, by passing ‘DatabaseType.SqlServer2012’ for example into the Database constructor. This will change the way the paging works in this case.</p>
<p>One of the latest features that has made it into 2.0 is the ability to use LINQ to specify simple where clauses, ordering and paging when fetching a single object. For example:</p>
<pre class="csharpcode">Database.FetchBy&lt;User&gt;(sql =&gt; sql.Where(x =&gt; x.Name == <span class="str">&quot;Bob&quot;</span>)
                                 .OrderBy(x =&gt; x.UserId)
                                 .Limit(10, 10))</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>There is also a FetchWhere&lt;&gt; which only takes a where expression.</p>
<p>Thanks again to all the contributors and if you have any issues be sure to raise them on <a href="https://github.com/schotime/NPoco/issues" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/schotime/NPoco/issues?referer=');">github</a>.</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2013/04/20/npoco-2-0/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>NPoco, PostgreSQL and DateTimeOffset</title>
		<link>http://schotime.net/blog/index.php/2013/03/13/npoco-postgresql-and-datetimeoffset/</link>
		<comments>http://schotime.net/blog/index.php/2013/03/13/npoco-postgresql-and-datetimeoffset/#comments</comments>
		<pubDate>Wed, 13 Mar 2013 02:23:25 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[DateTime]]></category>
		<category><![CDATA[NPoco]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[TimeStampTz]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/?p=151</guid>
		<description><![CDATA[Setting up PostgreSQL to run with NPoco is very simple. Firstly you need to install the Npgsql driver from NuGet. From the Package Manager Console type: Install-Package Npgsql Once this has been installed, we need to make a change to the web.config. &#60;system.data&#62; &#60;DbProviderFactories&#62; &#60;add name=&#34;Npgsql Data Provider&#34; invariant=&#34;Npgsql&#34; description=&#34;Data Provider for PostgreSQL&#34; type=&#34;Npgsql.NpgsqlFactory, Npgsql&#34;]]></description>
				<content:encoded><![CDATA[<p>Setting up PostgreSQL to run with NPoco is very simple. Firstly you need to install the Npgsql driver from NuGet. From the Package Manager Console type:</p>
<pre class="csharpcode">Install-Package Npgsql</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>Once this has been installed, we need to make a change to the web.config.</p>
<pre class="csharpcode">  <span class="kwrd">&lt;</span><span class="html">system.data</span><span class="kwrd">&gt;</span>
    <span class="kwrd">&lt;</span><span class="html">DbProviderFactories</span><span class="kwrd">&gt;</span>
      <span class="kwrd">&lt;</span><span class="html">add</span> <span class="attr">name</span><span class="kwrd">=&quot;Npgsql Data Provider&quot;</span> 
           <span class="attr">invariant</span><span class="kwrd">=&quot;Npgsql&quot;</span> 
           <span class="attr">description</span><span class="kwrd">=&quot;Data Provider for PostgreSQL&quot;</span> 
           <span class="attr">type</span><span class="kwrd">=&quot;Npgsql.NpgsqlFactory, Npgsql&quot;</span> <span class="kwrd">/&gt;</span>
    <span class="kwrd">&lt;/</span><span class="html">DbProviderFactories</span><span class="kwrd">&gt;</span>
  <span class="kwrd">&lt;/</span><span class="html">system.data</span><span class="kwrd">&gt;</span></pre>
<p>Now we are setup to create our connection string. Here is a sample one.</p>
<pre class="csharpcode">&lt;add name=<span class="str">&quot;Conn&quot;</span> 
    connectionString=<span class="str">&quot;Server=localhost;Database=db;User Id=user1;<br />                      Password=user1;Use Extended Types=true&quot;</span> 
    providerName=<span class="str">&quot;Npgsql&quot;</span>/&gt;</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 important part here is that you use the “User Extended Types=true”. This will return “TimeStampTz” types using Npgsql’s own type “NpgsqlTimeStampTZ” instead of a plain DateTime. <strong>Note: </strong>Npgsql does not automatically convert “timestamptz” types to DateTimeOffset, but using NPoco’s built in Mapper we can do this ourselves.</p>
<pre class="csharpcode"><span class="kwrd">if</span> (DestType == <span class="kwrd">typeof</span>(DateTimeOffset) || DestType == <span class="kwrd">typeof</span>(DateTimeOffset?)
    || DestType == <span class="kwrd">typeof</span>(DateTime) || DestType == <span class="kwrd">typeof</span>(DateTime?))
{
    <span class="kwrd">return</span> x =&gt;
    {
        <span class="kwrd">if</span> (x <span class="kwrd">is</span> NpgsqlTimeStampTZ)
        {
            <span class="kwrd">if</span> (DestType == <span class="kwrd">typeof</span>(DateTime))
                <span class="kwrd">return</span> (DateTime)((NpgsqlTimeStampTZ)x);
            <span class="kwrd">if</span> (DestType == <span class="kwrd">typeof</span>(DateTime?))
                <span class="kwrd">return</span> (DateTime?)((NpgsqlTimeStampTZ)x);
            <span class="kwrd">if</span> (DestType == <span class="kwrd">typeof</span>(DateTimeOffset))
                <span class="kwrd">return</span> (DateTimeOffset)((NpgsqlTimeStampTZ)x);
            <span class="kwrd">if</span> (DestType == <span class="kwrd">typeof</span>(DateTimeOffset?))
                <span class="kwrd">return</span> (DateTimeOffset?)((NpgsqlTimeStampTZ)x);
        }
        <span class="kwrd">if</span> (x <span class="kwrd">is</span> NpgsqlTimeStamp)
        {
            <span class="kwrd">if</span> (DestType == <span class="kwrd">typeof</span>(DateTime))
                <span class="kwrd">return</span> (DateTime)((NpgsqlTimeStamp)x);
            <span class="kwrd">if</span> (DestType == <span class="kwrd">typeof</span>(DateTime?))
                <span class="kwrd">return</span> (DateTime?)((NpgsqlTimeStamp)x);
        }
        <span class="kwrd">if</span> (x <span class="kwrd">is</span> NpgsqlDate)
        {
            <span class="kwrd">if</span> (DestType == <span class="kwrd">typeof</span>(DateTime))
                <span class="kwrd">return</span> (DateTime)((NpgsqlDate)x);
            <span class="kwrd">if</span> (DestType == <span class="kwrd">typeof</span>(DateTime?))
                <span class="kwrd">return</span> (DateTime?)((NpgsqlDate)x);
        }

        <span class="kwrd">return</span> x;
    };
}</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>Here we check if the Destination Type is “DateTime” or “DateTimeOffset” and convert the Npgsql type into the CLR type. To wire this Mapper up we do the following:</p>
<pre class="csharpcode">var db = <span class="kwrd">new</span> Database(<span class="str">&quot;Conn&quot;</span>) { Mapper = <span class="kwrd">new</span> Mapper() };</pre>
<p>Usually I will create a static method that will create my Database so that I don’t have to write this every time. eg.</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> DbHelper
{
    <span class="kwrd">public</span> <span class="kwrd">static</span> IDatabase GetDb()
    {
        <span class="kwrd">return</span> <span class="kwrd">new</span> Database(<span class="str">&quot;Conn&quot;</span>) { Mapper = <span class="kwrd">new</span> Mapper() };
    }
}</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>Now I can call DbHelper.GetDb() everywhere I need my database and the mapper will be plugged in appropriately.</p>
<p>As you can see, it is very easy to get up and running with NPoco and PostgreSQL. Please leave a comment if you have any questions.</p>
<p>Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2013/03/13/npoco-postgresql-and-datetimeoffset/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NPoco and MiniProfiler</title>
		<link>http://schotime.net/blog/index.php/2013/03/12/npoco-and-miniprofiler/</link>
		<comments>http://schotime.net/blog/index.php/2013/03/12/npoco-and-miniprofiler/#comments</comments>
		<pubDate>Tue, 12 Mar 2013 10:42:53 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[MiniProfiler]]></category>
		<category><![CDATA[NPoco]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/?p=150</guid>
		<description><![CDATA[Now that you have NPoco installed, being able to see exactly what queries were run and how they performed can make a huge difference in the overall performance of your site. MiniProfiler is an awesome project by Sam Saffron that can easily profile your site and SQL queries. It is very easy to install and]]></description>
				<content:encoded><![CDATA[<p>Now that you have <a href="https://nuget.org/packages/NPoco/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/nuget.org/packages/NPoco/?referer=');">NPoco</a> installed, being able to see exactly what queries were run and how they performed can make a huge difference in the overall performance of your site.</p>
<p><a href="http://miniprofiler.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/miniprofiler.com/?referer=');">MiniProfiler</a> is an awesome project by <a href="http://samsaffron.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/samsaffron.com/?referer=');">Sam Saffron</a> that can easily profile your site and SQL queries. It is very easy to install and there is heaps of documentation at its <a href="http://miniprofiler.com/" target="_blank" onclick="pageTracker._trackPageview('/outgoing/miniprofiler.com/?referer=');">home page</a>.</p>
<p>To install MiniProfiler type <em>Install-Package MiniProfiler</em> in the Package Manager Console.</p>
<p>So how do you wire it up to NPoco? That’s also very easy.</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> TheDatabase : Database
{
    <span class="kwrd">public</span> TheDatabase(<span class="kwrd">string</span> connectionStringName) 
        : <span class="kwrd">base</span>(connectionStringName) {}

    <span class="kwrd">public</span> <span class="kwrd">override</span> IDbConnection OnConnectionOpened(IDbConnection conn)
    {
        <span class="kwrd">return</span> <span class="kwrd">new</span> ProfiledDbConnection((DbConnection) conn, MiniProfiler.Current);
    }
}</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>Create a class that inherits from Database and override the OnConnectionOpened returning a new ProfiledDbConnection. Now instantiate your new class instead of Database when running queries.</p>
<p>As long as you have the @MiniProfiler.RenderIncludes() in your layout and MiniProfiler is started each request as per the installation instructions then your queries should be displayed in the top corner.</p>
<p>Let me know how you get on, and thank <a href="http://twitter.com/SamSaffron" target="_blank" onclick="pageTracker._trackPageview('/outgoing/twitter.com/SamSaffron?referer=');">Sam</a> for his awesome project.&#160; <br />Adam</p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2013/03/12/npoco-and-miniprofiler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing NPoco</title>
		<link>http://schotime.net/blog/index.php/2013/02/10/introducing-npoco/</link>
		<comments>http://schotime.net/blog/index.php/2013/02/10/introducing-npoco/#comments</comments>
		<pubDate>Sun, 10 Feb 2013 00:09:11 +0000</pubDate>
		<dc:creator>Schotime</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[NPoco PetaPoco MicroORM SQL]]></category>

		<guid isPermaLink="false">http://schotime.net/blog/?p=146</guid>
		<description><![CDATA[NPoco is the new library from my PetaPoco branch. If you don’t know what PetaPoco is, it is a MicroORM that enables quick and fast database access using raw sql. Why did I create this library? Well there was becoming too much divergence and it was always a pain that I couldn’t obtain my branch]]></description>
				<content:encoded><![CDATA[<p><a href="https://github.com/schotime/NPoco" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/schotime/NPoco?referer=');">NPoco</a> is the new library from my <a href="https://github.com/schotime/PetaPoco" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/schotime/PetaPoco?referer=');">PetaPoco branch</a>. If you don’t know what PetaPoco is, it is a MicroORM that enables quick and fast database access using raw sql. Why did I create this library? Well there was becoming too much divergence and it was always a pain that I couldn’t obtain my branch through NuGet. </p>
<p>Currently I’m working on V2 which is available now on <a href="http://nuget.org/packages/NPoco" target="_blank" onclick="pageTracker._trackPageview('/outgoing/nuget.org/packages/NPoco?referer=');">NuGet</a> if you use the –Pre console switch or by selecting “Include Prerelease” in Visual Studio. This does not include the T4 templates. I do take pull requests if you like this feature of PetaPoco and want it in NPoco.</p>
<p>There is also a fair bit of documentation about NPoco located at the <a href="https://github.com/schotime/NPoco/wiki" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/schotime/NPoco/wiki?referer=');">Wiki</a>. It includes basic documentation of how to use the library as well as the features only in NPoco. Some of these include.</p>
<ol>
<li>Query onto an existing object </li>
<li>One-to-Many query helpers </li>
<li>Mapping to Nested Objects query helpers </li>
<li>Dictionary&lt;string, object&gt; and object[] queries for dynamic results </li>
<li>Change tracking for updates </li>
<li>Composite Primary Key support </li>
<li>Queries that returns Multiple Result Sets </li>
<li>Fluent Mappings including Conventional based mappings </li>
<li>Version column support </li>
<li>IDatabase interface </li>
<li>Sql Templating </li>
</ol>
<p>I’m still finalising all the documentation for these features, so if documentation doesn’t exist for one of the let me know and I will prioritise that feature.</p>
<p>The code is also available at <a href="https://github.com/schotime/NPoco" target="_blank" onclick="pageTracker._trackPageview('/outgoing/github.com/schotime/NPoco?referer=');">Github</a>, so go have a look, give it a try, send me a pull request and let me know how you get on.</p>
<p>Adam</p>
<p><em>** I did try to get my changes for PetaPoco merged back in to the main project, however I feel this will be better for my changes going forward.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://schotime.net/blog/index.php/2013/02/10/introducing-npoco/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<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>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> Application_Start()
{
    FluentMappingConfiguration.Scan(x =&gt;
    {
        x.Assembly(<span class="kwrd">typeof</span>(MvcApplication).Assembly);
    });
}</pre>
<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>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> Application_Start()
{
    FluentMappingConfiguration.Scan(x =&gt;
    {
        x.Assembly(<span class="kwrd">typeof</span>(MvcApplication).Assembly);
        x.IncludeTypes(type =&gt; type.Namespace == <span class="str">&quot;MvcApplication.Models.Db&quot;</span>);
    });
}</pre>
<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>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> Application_Start()
{
    FluentMappingConfiguration.Scan(x =&gt;
    {
        x.Assembly(<span class="kwrd">typeof</span>(MvcApplication).Assembly);
        x.IncludeTypes(type =&gt; type.Namespace == <span class="str">&quot;MvcApplication.Models.Db&quot;</span>);
        x.TablesNamed(type =&gt; <span class="str">&quot;t_&quot;</span> + type);
        x.PrimaryKeysNamed(type =&gt; type + <span class="str">&quot;Id&quot;</span>);
        x.PrimaryKeysAutoIncremented(type =&gt; <span class="kwrd">true</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>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>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> Application_Start()
{
    FluentMappingConfiguration.Scan(x =&gt;
    {
        x.Assembly(<span class="kwrd">typeof</span>(MvcApplication).Assembly);
        x.IncludeTypes(type =&gt; type.Namespace == <span class="str">&quot;MvcApplication.Models.Db&quot;</span>);
        x.TablesNamed(type =&gt; <span class="str">&quot;t_&quot;</span> + type);
        x.PrimaryKeysNamed(type =&gt; type + <span class="str">&quot;Id&quot;</span>);
        x.PrimaryKeysAutoIncremented(type =&gt; <span class="kwrd">true</span>);
        x.Columns.Named(prop =&gt;
            prop.PropertyType == <span class="kwrd">typeof</span>(DateTime) ? <span class="str">&quot;d_&quot;</span> + prop.Name : prop.Name);
    });
}</pre>
<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>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> Application_Start()
{
    FluentMappingConfiguration.Scan(x =&gt;
    {
        x.Assembly(<span class="kwrd">typeof</span>(MvcApplication).Assembly);
        x.IncludeTypes(type =&gt; type.Namespace == <span class="str">&quot;MvcApplication.Models.Db&quot;</span>);
        x.WithSmartConventions();
    });
}</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>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>
<pre class="csharpcode"><span class="kwrd">protected</span> <span class="kwrd">void</span> Application_Start()
{
    FluentMappingConfiguration.Scan(x =&gt;
    {
        x.Assembly(<span class="kwrd">typeof</span>(MvcApplication).Assembly);
        x.IncludeTypes(type =&gt; type.Namespace == <span class="str">&quot;MvcApplication.Models.Db&quot;</span>);
        x.TablesNamed(type =&gt; <span class="str">&quot;t_&quot;</span> + type);
        x.PrimaryKeysNamed(type =&gt; type + <span class="str">&quot;Id&quot;</span>);
        x.PrimaryKeysAutoIncremented(type =&gt; <span class="kwrd">true</span>);
        x.Columns.Named(prop =&gt;
            prop.PropertyType == <span class="kwrd">typeof</span>(DateTime) ? <span class="str">&quot;d_&quot;</span> + prop.Name : prop.Name);

        x.OverrideMappingsWith(<span class="kwrd">new</span> MappingOverrides());
    });
}

<span class="kwrd">public</span> <span class="kwrd">class</span> MappingOverrides : Mappings
{
    <span class="kwrd">public</span> MappingOverrides()
    {
        For&lt;Abc&gt;().TableName(<span class="str">&quot;Abcies&quot;</span>)
                    .PrimaryKey(<span class="str">&quot;MyAbcId&quot;</span>)
                    .Columns(x =&gt; x.Column(y=&gt;y.Name).Ignore());
    }
}</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>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>3</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>6</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>8</slash:comments>
		</item>
	</channel>
</rss>
