Monthly Archives: January 2013

How to get C# LINQ working in Visual Studio 2010 and SQL Server Express

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _130122_LINQTest4
  class Program
    static void Main(string[] args)

      // Creates a new database in SQL Server Management Studio
      // Created a table called Skateboards

      // Added a new Data Connection from the Database Explorer tab

      // Top Menu > Project > Add New Item > Linq to SQL classes
      // Said 'Yes' to copy local copy to output path -- hence why the .mdf
      // is now in the Solution Explorer

      // From the Database Explorer, dragged my tables into the .dbml viewer
      // what this does is it creates the entity code so I can use LINQ

      using (var db = new DataClasses1DataContext())
        var skateboards = from r in db.Skateboards select r;