<feed xmlns="http://www.w3.org/2005/Atom"><title type="text">Lambda42 Blog</title><subtitle type="text">Blog feed for Lambda42, a web development company based in Tunbridge Wells, UK</subtitle><id>http://www.lambda42.co.uk/</id><updated>2010-07-29T16:49:36+01:00</updated><author><name>Martyn Osborne</name><uri>http://www.zzdtri.com</uri><email>martyn@lambda42.co.uk</email></author><link rel="alternate" href="http://lambda42.co.uk/"/><entry><id>http://www.lambda42.co.uk/blog/adventures-with-the-entity-framework-and-the-repository-pattern/show</id><title type="text">Adventures with the Entity Framework and the Repository Pattern</title><updated>2009-08-20T01:09:32+01:00</updated><link rel="alternate" href="http://www.lambda42.co.uk/blog/adventures-with-the-entity-framework-and-the-repository-pattern/show"/><content type="html">&lt;p&gt;So far in my applications, I have been using the Entity Framework for object persistence (why? SQLite is why).&amp;#160; Unfortunately, I also like to write lots of unit tests.&amp;nbsp; Normally, this would be a problem, as the entity container would be coupled to the controllers.&lt;/p&gt;  &lt;h2&gt;How I implement the Repository Pattern&lt;/h2&gt;  &lt;p&gt;To get around this, I have been using the repository pattern to great effect.&lt;/p&gt;  &lt;p&gt;I start by creating my IRepository&amp;lt;T&amp;gt; generic interface:&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre&gt;&lt;span class="lnum"&gt;   1:  &lt;/span&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;interface&lt;/span&gt; IRepository&amp;lt;T&amp;gt;&lt;/pre&gt;&#xD;
&#xD;
  &lt;pre&gt;&lt;span class="lnum"&gt;   2:  &lt;/span&gt;    {&lt;/pre&gt;&#xD;
&#xD;
  &lt;pre&gt;&lt;span class="lnum"&gt;   3:  &lt;/span&gt;        T Single(Func&amp;lt;T, &lt;span class="kwrd"&gt;bool&lt;/span&gt;&amp;gt; filter);&lt;/pre&gt;&#xD;
&#xD;
  &lt;pre&gt;&lt;span class="lnum"&gt;   4:  &lt;/span&gt;        IQueryable&amp;lt;T&amp;gt; All { get; }&lt;/pre&gt;&#xD;
&#xD;
  &lt;pre&gt;&lt;span class="lnum"&gt;   5:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&#xD;
&#xD;
  &lt;pre&gt;&lt;span class="lnum"&gt;   6:  &lt;/span&gt;        &lt;span class="kwrd"&gt;void&lt;/span&gt; Insert(T entity);&lt;/pre&gt;&#xD;
&#xD;
  &lt;pre&gt;&lt;span class="lnum"&gt;   7:  &lt;/span&gt;        &lt;span class="kwrd"&gt;void&lt;/span&gt; Remove(T entity);&lt;/pre&gt;&#xD;
&#xD;
  &lt;pre&gt;&lt;span class="lnum"&gt;   8:  &lt;/span&gt;&amp;nbsp;&lt;/pre&gt;&#xD;
&#xD;
  &lt;pre&gt;&lt;span class="lnum"&gt;   9:  &lt;/span&gt;        &lt;span class="kwrd"&gt;void&lt;/span&gt; Commit();&lt;/pre&gt;&#xD;
&#xD;
  &lt;pre&gt;&lt;span class="lnum"&gt;  10:  &lt;/span&gt;    }&lt;/pre&gt;&lt;/div&gt;&lt;style type="text/css"&gt;&#xD;
&#xD;
.csharpcode, .csharpcode pre&#xD;
{&#xD;
	font-size: small;&#xD;
	color: black;&#xD;
	font-family: consolas, "Courier New", courier, monospace;&#xD;
	background-color: #ffffff;&#xD;
	/*white-space: pre;*/&#xD;
}&#xD;
.csharpcode pre { margin: 0em; }&#xD;
.csharpcode .rem { color: #008000; }&#xD;
.csharpcode .kwrd { color: #0000ff; }&#xD;
.csharpcode .str { color: #006080; }&#xD;
.csharpcode .op { color: #0000c0; }&#xD;
.csharpcode .preproc { color: #cc6633; }&#xD;
.csharpcode .asp { background-color: #ffff00; }&#xD;
.csharpcode .html { color: #800000; }&#xD;
.csharpcode .attr { color: #ff0000; }&#xD;
.csharpcode .alt &#xD;
{&#xD;
	background-color: #f4f4f4;&#xD;
	width: 100%;&#xD;
	margin: 0em;&#xD;
}&#xD;
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;p&gt;People could say that the Single method is rather pointless, but I like to have it there.&amp;nbsp; You could also comment on the lack of an Update method – but the entity framework’s change tracking does a good job.&amp;nbsp; Other people would say this is bad, as the repository is being tied to the entity framework, but that is not the reason I am doing this.&lt;/p&gt;&lt;p&gt;Originally, I would have an interface per entity, but the generic interface solves all the duplication I was seeing.&lt;/p&gt;&lt;p&gt;This interface is extremely simple to implement, and solves my Entity Framework + TDD problems.&lt;/p&gt;&lt;p&gt;Regardless, roll on EF 4.0 POCOs!&lt;/p&gt;</content></entry><entry><id>http://www.lambda42.co.uk/blog/visual-studio-2010-jquery-intellisense/show</id><title type="text">Visual Studio 2010 jQuery intellisense</title><updated>2009-06-13T00:14:19+01:00</updated><link rel="alternate" href="http://www.lambda42.co.uk/blog/visual-studio-2010-jquery-intellisense/show"/><content type="html">&lt;p&gt;Just a quick post for something I only today noticed in the Visual Studio 2010 beta – and its damned cool.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.lambda42.co.uk/images/posts/WindowsLiveWriter/VisualStudio2010jQueryintellisense_356/image_2.png"&gt;&lt;img style="border: 0px none ; display: inline;" title="image" alt="image" src="http://www.lambda42.co.uk/images/posts/WindowsLiveWriter/VisualStudio2010jQueryintellisense_356/image_thumb.png" height="332" width="433" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;Yeah, that’s pretty awesome.&lt;/p&gt;</content></entry><entry><id>http://www.lambda42.co.uk/blog/the-problem-with-aspnet-mvc--spaghetti-code/show</id><title type="text">The problem with ASP.NET MVC - "spaghetti code"</title><updated>2009-04-09T17:59:09+01:00</updated><link rel="alternate" href="http://www.lambda42.co.uk/blog/the-problem-with-aspnet-mvc--spaghetti-code/show"/><content type="html">&lt;p&gt;I apologise in advance if this post seems slightly incoherent - I write this whilst on a train, and its quite a bumpy ride.&amp;#160; Also, another disclaimer - the code you're about to see will be soon heavily refactored and improved; don't expect it in this state to be amazing!&amp;nbsp; For one, truncating the post content will be moved to the model level, and the post mark-up will be moved to a user control.&lt;/p&gt;  &lt;p&gt;Consider the following mark-up:&lt;/p&gt;  &lt;pre class="brush: xml;"&gt;&amp;lt;% foreach (Blog42.Model.Post p in Model.Posts) { %&amp;gt;&#xD;
&#xD;
&amp;lt;%-- Post begin --%&amp;gt;&#xD;
&#xD;
&amp;lt;div class="leftcontent"&amp;gt;&#xD;
    &amp;lt;h1&amp;gt;&amp;lt;%= Html.ActionLink(p.Title,"Show", new { title = p.URI }) %&amp;gt;&amp;lt;/h1&amp;gt;&#xD;
    &amp;lt;h2&amp;gt;Posted by &amp;lt;%= Html.ActionLink(p.User.UserName,"ByUser", new { username = p.User.UserName }) %&amp;gt;&#xD;
&#xD;
     at &amp;lt;%= p.Date %&amp;gt;&amp;lt;/h2&amp;gt;&#xD;
    &#xD;
    &amp;lt;div class="blogcontent"&amp;gt;&#xD;
        &amp;lt;%= p.TruncatedContent %&amp;gt;&#xD;
        &amp;lt;% if (p.IsTruncated) { %&amp;gt;&#xD;
            &amp;lt;%= Html.ActionLink("Read More","Show", new { title = p.URI }) %&amp;gt;&#xD;
&#xD;
        &amp;lt;% } %&amp;gt;&#xD;
    &amp;lt;/div&amp;gt;&#xD;
                    &#xD;
    &amp;lt;%= Html.RenderTags(p) %&amp;gt;&#xD;
    &#xD;
    &amp;lt;span&amp;gt;&amp;lt;%= Html.ActionLink("Comments (" + p.Comments.Count + ")","Show", new { title = p.URI }) %&amp;gt;&amp;lt;/span&amp;gt;&#xD;
&#xD;
&amp;lt;/div&amp;gt;&#xD;
&#xD;
&amp;lt;%-- Post end --%&amp;gt;&#xD;
&#xD;
&amp;lt;% } %&amp;gt;&lt;/pre&gt;&lt;p&gt;There are a couple of things here that I absolutely hate (and will soon in part be refactored) - the selection statement and the massive amount of &amp;lt;%= %&amp;gt;.&amp;nbsp; For most people, they will see nothing wrong with this, and will keep doing it.&amp;nbsp; In the end I believe this will lead to an un-maintainable application with unreadable mark-up.&lt;/p&gt;&lt;p&gt;Writing an helper is the solution to this - note that I have moved the tag building to a helper.&lt;/p&gt;&lt;pre class="brush: csharp;"&gt;public static string RenderTags(this HtmlHelper helper, Post post)&#xD;
{&#xD;
    StringBuilder builder = new StringBuilder();&#xD;
&#xD;
    if (post.Tags.Count &amp;gt;= 1)&#xD;
    {&#xD;
        builder.Append("&amp;lt;p&amp;gt;&amp;lt;strong&amp;gt;Tags:&amp;lt;/strong&amp;gt;");&#xD;
&#xD;
        int tagNumber = 0;&#xD;
&#xD;
        foreach (Tag tag in post.Tags)&#xD;
        {&#xD;
            tagNumber++;&#xD;
&#xD;
            builder.Append(" ");&#xD;
            builder.Append(helper.ActionLink(tag.Name,"ByTag","Post",new { tag = tag.Name }, null));&#xD;
&#xD;
            if (tagNumber != post.Tags.Count)&#xD;
                builder.Append(" | ");&#xD;
        }&#xD;
&#xD;
        builder.Append("&amp;lt;/p&amp;gt;");&#xD;
    }&#xD;
&#xD;
    return builder.ToString();&#xD;
}&lt;/pre&gt;&lt;p&gt;This however, is also what I believe to be suboptimal - note the snippets of mark-up inside the code!&amp;nbsp; &lt;/p&gt;&lt;p&gt;However, it is an improvement, and for the time being I believe a necessary evil.&amp;nbsp; It does improve the readability of the mark-up, and introduces some semblance of reusability in the sense that I can use the same helper whenever I want to build a list of tags.&lt;/p&gt;&#xD;
                &#xD;
        &#xD;
    </content></entry><entry><id>http://www.lambda42.co.uk/blog/my-experiences-with-aspnet-dynamic-data/show</id><title type="text">My experiences with ASP.NET Dynamic Data</title><updated>2009-03-23T14:47:59Z</updated><link rel="alternate" href="http://www.lambda42.co.uk/blog/my-experiences-with-aspnet-dynamic-data/show"/><content type="html">&lt;p&gt;Not long ago I had no idea what the point of ASP.NET Dynamic Data was.&amp;#160; I simply could not 'grok' it, until very recently when I tried using it for a client's CMS. &lt;/p&gt;  &lt;p&gt;Basically, Dynamic Data turned this: &lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.lambda42.co.uk/images/posts/WindowsLiveWriter/MyexperienceswithASP.NETDynamicData_CF0D/image_2.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://www.lambda42.co.uk/images/posts/WindowsLiveWriter/MyexperienceswithASP.NETDynamicData_CF0D/image_thumb.png" height="478" width="635" /&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;  &lt;p&gt;Into this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.lambda42.co.uk/images/posts/WindowsLiveWriter/MyexperienceswithASP.NETDynamicData_CF0D/image_4.png"&gt;&lt;img style="border-width: 0px; display: inline;" title="image" alt="image" src="http://www.lambda42.co.uk/images/posts/WindowsLiveWriter/MyexperienceswithASP.NETDynamicData_CF0D/image_thumb_1.png" height="168" width="636" /&gt;&lt;/a&gt; &lt;/p&gt;    &lt;p&gt;Using only three lines of code in the Global.asax.cs:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;MetaModel model = &lt;span class="kwrd"&gt;new&lt;/span&gt; MetaModel();&#xD;
&#xD;
model.RegisterContext(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(BlogModel),&lt;/pre&gt;&lt;pre class="csharpcode"&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ContextConfiguration() { ScaffoldAllTables = &lt;span class="kwrd"&gt;true&lt;/span&gt; });&lt;/pre&gt;&lt;p&gt;The site that has been generated for me lets my edit all my tables, filter by foreign keys, add new rows, view related rows, and more.&amp;nbsp; All from three lines of code.&amp;nbsp; Absolutely incredible.&lt;/p&gt;</content></entry><entry><id>http://www.lambda42.co.uk/blog/aspnet-mvc-released/show</id><title type="text">ASP.NET MVC released</title><updated>2009-03-20T14:12:03Z</updated><link rel="alternate" href="http://www.lambda42.co.uk/blog/aspnet-mvc-released/show"/><content type="html">&lt;p&gt;Nice to see that finally ASP.NET MVC has been released!&amp;#160; Been using it since the very first preview, and it's been a blast.&lt;/p&gt;  &lt;p&gt;Can grab it &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=53289097-73ce-43bf-b6a6-35e00103cb4b&amp;amp;displaylang=en"&gt;here.&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Also, noticed that Silverlight 3 has been released as a beta, already.&amp;nbsp; This is a bit annoying as Silverlight 2 was only released 5 months ago.&amp;nbsp; Too many technologies to master, so little time!&lt;/p&gt;</content></entry><entry><id>http://www.lambda42.co.uk/blog/consuming-adonet-data-services-from-jquery/show</id><title type="text">Consuming ADO.NET Data Services from jQuery</title><updated>2009-03-10T18:23:28Z</updated><link rel="alternate" href="http://www.lambda42.co.uk/blog/consuming-adonet-data-services-from-jquery/show"/><content type="html">&lt;p&gt;One thing that has certainly sped up my development time is using ADO.NET Data Services with my AJAX.&amp;#160; Instead of having to build controller actions or a web service to grab the data, i can just consume it from the data service directly.&lt;/p&gt;  &lt;p&gt;I'm going to assume you know how to set up a Data Service - it really isn't too hard.&lt;/p&gt;  &lt;p&gt;Actually getting jQuery to consume it isn't much harder. All you need is the standard '$.getJSON' function, and you're flying.&lt;/p&gt;  &lt;p&gt;One thing that tripped me up, however, was the data that was returned from the service: a quick glance shows that the data is wrapped in a 'd' object.&lt;/p&gt;  &lt;div class="csharpcode"&gt;   &lt;pre class="alt"&gt;{ &lt;span class="str"&gt;"d"&lt;/span&gt; : [ (data here) ] }&lt;/pre&gt;&lt;/div&gt;</content></entry><entry><id>http://www.lambda42.co.uk/blog/adonet-data-services/show</id><title type="text">ADO.NET Data Services</title><updated>2009-02-12T18:25:23Z</updated><link rel="alternate" href="http://www.lambda42.co.uk/blog/adonet-data-services/show"/><content type="html">&lt;p&gt;Been playing around with ADO.NET Data Services this morning - really cool how you can point it at your (Entity Framework in this case) data model, and it fully exposes it via a web service.&lt;/p&gt;  &lt;p&gt;Planning on using it to replace my current MVC JSON-returning controllers.&amp;#160; Shouldn't be that much more difficult, it cleans up the controllers, and in the future will save masses amount of time.&amp;nbsp; What's not to like?&lt;/p&gt;</content></entry></feed>