Tag Archives: source code

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


AccessViolationException, EntryPointNotFoundException, and Change Tracking Error on SyncAgent.Synchronize()

Recently I was working on a data-driven application which needed to continue operating in sometimes-disconnected environments. In theory, this is a fairly simple problem to solve with .NET Sync Framework using a “Local Data Cache” implementation of SQL Server CE file and SQL Server database–a solution that I have implemented several times in the past.

Never have I had to jump through so many crazy hoops.
Continue reading


Hate Unity, Upgraded to Ubuntu 11.10…now to fix the UI

As many folks, I do not like the Unity interface in the latest versions of Ubuntu. In Ubuntu 11.04, I had used the “Classic” mode when logging in, but after upgrading to 11.10 I’ve had to take additional steps to avoid the Unity UI.
Continue reading