Category Archives: Professional

Performance testing LINQ to Objects Except Method

When .NET introduced LINQ and lambdas, I was blown away by the efficiency improvements in writing code. But, after reading countless articles online about how horribly slow and inefficient LINQ (even to objects) was compared with just plain for-loops, I’ve always felt guilty about using it.

The other day, however, I wanted to see how much slower linq would be in comparing 2 lists of objects to find all of the items from list1 that were not in list2. LINQ has an extension method called “Except” just for this.

I coded the solution in LINQ, and then coded a few “solutions” using pre-LINQ techniques…spoiler alert: LINQ was the best for large sets of objects.
Continue reading


Generate MERGE scripts for all tables in a database

If you have been using the Database Projects (.sqlproj) in Visual Studio 2010 to maintain your database schema in version control, you probably need a good way to store static data for your application in version control as well. There are pre and post deployment scripts to handle that, but one of the cool things about SQL Server 2008 is that it allows for MERGE statements to perform the correct operation on the database side based on the state of the data in your target DB.

This let’s you specify what the static (also called seed, lookup table, and default) data needs to look like in a declarative way!

It’s very powerful, but often times by the time you get around to storing your database in version control, you already have tons of tables with tons of static data in there… and it would be a pain to hand-code all of the SQL MERGE statements.
Continue reading


Entity Framework Mocking template with IDisposable implementation

I’m working on a C#/.NET StackOverflow clone and wanted to create mock data contexts for unit testing with Entity Framework.

I found a great T4 template that does this from Rab Hallett’s blog, but it did not include the IDisposable interfaces used by the .NET ObjectContext.

I’ve modified the template to include these additions to the generated Mock context so that I can now use the interface in a using block.

            using (var db = DataContextFactory.CreateContentContext(_isMock))
            { //actual code goes here
            }

The entire T4 template (ContentModelGenerator.Context.tt) is on my bitbucket if you want to use it.


HEAD.JS, Twitter Bootstrap, Django, and Google App Engine… Oh my!

After watching an awesome presentation about Twitter Bootstrap at this year’s CodeStock, I really wanted to give it a try.

As with most web projects that I want to deploy rapidly, I turned to Django (nonrel) and Google App Engine and started tweaking the default template I’ve got for creating a new website. I use mediagenerator¬†to combine all of my JS into a single minified file which I include at the bottom of the page to ensure faster load times and so that the DOM is ready for my JS.

It only took a few minutes to make the updates to my template, and then I was ready to deploy and start playing.

Continue reading


Target SQL Server and SQL CE with the same Entity Framework objects while using Sync Framework

When developing a sometimes-disconnected application in .NET, you have the ability to create a “local data cache” (Sql CE file) and then synchronize this local database with a server database periodically (when connected) to keep the data relevant.

Of course to actually interact with the data from your .NET application, you will want to create a data model with Entity Framework. There are a few tricks that can make the whole process much simpler.
Continue reading


Manually running MongoDB in Kubuntu

When I am developing against MongoDB I don’t want the server to run all the time and use up my memory. Instead, what I do is manually start/stop the server and specify config files so that it can run on various data directories.

To set it up, I downloaded MongoDB to ~/Downloads, and then extracted to a directory where I keep various apps: ~/Apps/mongodb-linux-x86_64-2.0.1.

Inside the MongoDB directory is a bin directory. I create a symbolic link to everything there from my home bin directory (~/bin).

When I log in, the ~/.bashrc file in Kubuntu adds everything in ~/bin to the $PATH. This way I can easily run mongod from the bash manually and specify a config file for mongod to use (so I can switch between database directories easily for different projects).


Force Restart in Linux

When the computer freezes (as has happened multiple times under Ubuntu w/Unity to me), press ALT + PrintScreen/SysRq + R + E + I + S + U + B.