Using LINQPad to Query Stack Overflow

Update (2010-12-30): I have updated the OData URI locations below, because of a recent move and re-architecture by the StackExchange team.

In case you haven’t read, Stack Overflow and the rest of the Stack Exchange sites are now able to be queried using OData.  This is great because as Jeff points out in the blog post:

…if you just want to play with the data, it’s kind of tedious: you have to download the entire 700 plus megabyte archive, import it into some kind of database system — and only then can you even begin thinking about how to query out the results you’re looking for.

This hurdle has stopped me from performing some basic queries that I would like to know on the spot.  But that is no longer the case, and I am going to show you how you can get started querying Stack Overflow from a tool called LINQPad.

First Things, First

You need to download LINQPad, which is a general learning and development tool for composing and executing LINQ queries.  After you have downloaded and installed the application you will have a screen that looks like this:


Setting Up Stack Overflow OData

The next step is to add the OData endpoint for Stack Overflow, which is:

This is done by clicking on Add connection in the top left of LINQPad.  Which will give you a screen that looks like this:

Choose Data Context

Select WCF Data Services and click Next.  You will get a connection screen where you enter the endpoint for Stack Overflow that I described above:

LINQPad Connection

After entered click OK, and you will be taken back to the LINQPad application with a new connection to the Stack Overflow data source that lists all the available tables and fields that you can query.

LINQPad w/ Stack Overflow

Lets Have Some Fun Querying

Lets start with an easy query that we all should know.  Who is the number 1 Stack Overflow user?

Surprise it is Jon Skeet.

What about which user has the highest number of votes?

Not Jon Skeet, which is surprising.

What about down votes?

Another guy in the UK

Show my insightful comments with a score of 5 or greater?

I only have one :(


As you can see this is a very powerful way to get some quick answers out of Stack Overflow, and it is amazing that Microsoft, Azure, and Stack Overflow is able to bring all of this to us for free.

Also if interested they also offer OData endpoints for all of the other major Stack Exchange network of sites:

Post some of your interesting queries below.

Nick Berardi

In charge of Cloud Drive Desktop at @Amazon, Entrepreneur, Microsoft MVP, ASPInsider, co-founder and CTO of @CaddioApp, Father, and @SeriouslyOpen host