A Smarter Entity Framework Include Method

One of the things I have always disliked about Entity Framework and their support for LINQ is that while your whole LINQ statement is compile time checked to make sure you didn’t fat finger any SQL statement, the Include() statement is not. How many times has something like this happened to you? var account1001 = (new AccountEntities()) .Accounts.Include("Userx") .Where(account => account.Id == 1001) .SingleOrDefault(); You might have noticed in the above that I probably wanted “Users” instead of “Userx”. I don’t know about you but this happens to me all the time, and if the code was just compile time checks like the rest of the LINQ statement everything would be great and I would instantly catch the bug when the code was compiled. ...

February 27, 2011 · 2 min · 377 words · Nick Berardi

Entity Framework Repository Pattern

This is my first attempt at an Entity Framework (EF) based Repository Pattern. I took a stab at this while working on a new project, and I am really liking the ease of use this is providing me. So I thought I would share… Before I get started, I wanted to make a special call out to Dane Morgridge’s EF Repository on CodePlex which is based on T4 templates. His project originally got my gears turning as to how I would make my own repository pattern for EF. Also I wanted to pre-text this blog post with the actual code which I have posted up on GitHub Gist: ...

November 17, 2010 · 4 min · 800 words · Nick Berardi

Sometimes you just need to CodingHorror it!

The title of this post is a tongue-in-cheek reference to SubSonic’s inline query by the same name, which in turn is a reference to the blogger Jeff Atwood’s blog who you should all know. Rob Conery, the SubSonic project leader, named the inline query class CodingHorror after he allegedly read Jeff Atwood’s post titled Embracing Languages Inside Languages, in which he bestowed the virtues of inline SQL inside your code, instead of the standard bequeathed statement that I bet you all have heard “We do all database work in stored procedures.”. Jeff outlined his though process on ad-hoc vs stored procs as follows: ...

December 3, 2009 · 4 min · 672 words · Nick Berardi