LINQ, I'm not ready for you just yet

Today I was between features on the current project I'm working on, so I had some free time start researching some technologies I've been meaning to learn and start using. The topics at the top of my learning list are LINQ and MVC. I gave LINQ a few months to mature, so I figured it was a good time to investigate.

Boy Crying

(there is no emoticon to express my anger!)

The picture above shows how I felt when I started writing my first LINQ expression. The biggest problem was the fact that the latest version of ReSharper doesn't support any .NET 3.0+ language features. Not only does it not support LINQ, it's IntelliSense severely interrupts you while writing it. So much so that it makes it unusable.

I went ahead and downloaded the latest development build (Build 783). On their download page, it's listed as "Works here". That wasn't encouraging. It does work a little better with LINQ, but it's still a steaming pile of you know what (dog poop for the not-so-smart). This further reinforces my love/hate relationship with ReSharper.

Anyway, I was eventually able to write some LINQ code. A great tool to get started is LinqPad, which is basically a query analyzer but with LINQ expressions. Writing LINQ is very difficult with a SQL background, because everything is backwards. You think you know what you're doing, but you don't.

Right now, we're using NHibernate in the main project that I've been working on for the past couple of months. It's amazing, but there are a couple of things that would be nice:

  • Better optimization of queries - It looks like LINQ does an amazing job with this.
  • Batched reads & writes - LINQ does batched writes, but lazy loading by default. Maybe not as big a deal as I think.
  • Cross session saving - I spent hours battling with some code that loaded a complex object with relationships in one session, and then saved them in another. It appears that LINQ solves this, but I'll have to run some tests to be sure.
  • Less work generating mapping files and relationships.

One thing that is nice about LINQ to objects is the fact that it will generate all of the model classes, plus the glue that connects the model to the database. You can either use Visual Studio and drop the tables into a mapping file, or you can use SqlMetal to script the class generation.

One of the biggest questions I'm trying to answer write now, is how unit testing fits in with LINQ. We're currently testing our data access layer by using an in memory SQLite database, which let's us perform close to real world saves and loads. We also use interfaces for our data access methods, which makes it easy to create testable classes that can simply be supplied a database interface.

I'm also not sure if it even makes sense to put my LINQ queries in a data access layer. The code would almost seem trivial, and would just create a lack of flexibility. Ironically, it almost feels like you should use LINQ to query against your data access layer.

For now, there are more questions than answers. For now, I don't plan on retrofitting my last project with LINQ, but I'm going to investigate if it will be a good foundation for the data access logic in my next project. Of course if I go that route, you'll be sure to hear about it!

Like this post? Please share it!

See a mistake? Edit this post!

.NET XML DataSet Generator from a SQL Query

As promised, I've now made the .NET XML DataSet Generator available on Google Code.

.NET XML DataSet Generator

If anyone can think of a better name for the project, please let me know! It's really hard to convey what it actually does. On the project page, I put these basic steps, which should help make it clear:

  1. Run this program to execute a SQL statement
  2. Copy the resulting XML into a file in your .NET unit test project
  3. Embed the XML file you created
  4. In your test code, load the embedded XML, deserialize it back into a DataSet (code coming soon)

As the project matures a little bit, I'll have better documentation. I may even whip up a video demonstration. It's not really a fancy tool, but it does come in handy.

For example, let's say you have a database method that returns a DataSet containing a table of blog post items. You have another method that turns that DataSet into an array of post objects. I know that you're thinking you should normally use an OR mapper, but this is just an example, so please don't interrupt me!. This tool lets you create a serialized DataSet that you can use in a unit test, which will reconstitute the DataSet into the exact same thing your database method would have returned. You can now pass in a snapshot of real data into the method your testing. If you ARE using an OR mapper like NHibernate, this probably won't happen much, but when it does, this tool will come in handy.

Like this post? Please share it!

See a mistake? Edit this post!

Converted my blog from Blogger to Wordpress

Well I did it. I actually really liked using Blogger, and I had finally gotten my blog set up the way I liked. However, I just wanted a little more. I evaluated a couple of different solutions (including Subtext, which I use on my personal blog), and I decided to go with WordPress (the software, not the hosted service).

WordPress Logo

First off, I wanted to be able to have a little more control over some SEO aspects of my blog, such as using a robots.txt. The all in one SEO pack Wordpress plug-in seems to handle many of my requirements. Unlike Blogger, a lot of the non-content pages won't get indexed now (a good thing). See "Avoiding duplicate content with your site" for more information.

I also wanted to use the Apache mod_rewrite functionality, which is really an amazing tool. For example, I'm doing 301 redirects on all of the old Blogger archive pages, to the equivalent Wordpress archive URL's.

RewriteRule ^([d]{4})([d]{2})[d]{2}_archive.html$ /$1/$2 [R=301,L]
I also set up the Google Analtyics Plugin, which sets up some pretty neat tracking features. It's even supposed to track outgoing links, but it isn't working for me for some reason. I'll be checking with the author.

Overall, I'm very happy with the Wordpress platform. It's very simple and simply works like I would expect. Since it's one of the most popular blogging platforms, I know that support is just a Google away, and bugs shouldn't stay around too long. I also know that I can easily extend its functionality, or at least add content.

I'm hosting it on my dedicated server under Xampp. Installation of Apache, MySql, and Wordpress couldn't be easier. In fact, I had it up and running in about 10 minutes. The performance seems pretty good compared to Blogger. There are a lot less files being downloaded, which should really help. I also plan to enable gzip compression for some more speed, and I would like to get a caching plugin to avoid constant page regeneration.

Let me know what you think of the new site, and my new theme!

PS. Sorry to my RSS subscribers. When I switched to Wordpress, the RSS feed shows the posts as all being new.

Like this post? Please share it!

See a mistake? Edit this post!

Jason Young I'm Jason Young, software engineer. This blog contains my opinions, of which my employer - Microsoft - may not share.

@ytechieGitHubLinkedInStack OverflowPersonal VLOG