Linq to SQL Compact Edition (CE)

I got asked about doing this recently, and needed somewhere to point the individual to.

Presently, unfortunately, Linq to SQL Compact Edition is unsupported. Luckily though, it is quite easy to still perform Linq queries against SQL compact using the command line utility SqlMetal. SQL Compact Edition is very handy for single user applications or demos where you want to retain a very small application imprint, but not lose functionality. All that is required is that you have the object relational mapping (ORM) file that contains the Linq to SQL classes. This in Visual Studio is the .dbml file that is generated when you elect LinqToSQLClasses in the data menu.

Open up the Visual Studio command prompt by going to

You should have the following;

C:\Program Files\Microsoft Visual Studio 9.0\VC>

Enter ‘SqlMetal’ in the command prompt and take time to explore all the options available to you.

I simply want to create a .dbml file from my database which I have in my c:\ drive. You will want to point this to wherever your .sdf file is.

Enter the following path into the Visual Studio command prompt

SqlMetal /dbml:c:\Users\MyName\Documents\Northwind.dbml "C:\Users\MyName\Documents\Visual Studio 2008\Projects\Windows Forms\Code\Northwind\Northwind Database\Northwind.sdf"

Where the above is the format; SqlMetal /dbml:northwind.dbml northwind.sdf

Note that in vista you must specify the path through the ‘Users folder’. Failure to do this will result in a file access error.

As you can see my .dbml file was copied to my documents folder. I then copied this into my project. .To access the file I reference it in the constructor of the form thus;

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
    public partial class Form1 : Form
        NorthwindDataContext northwindDataContext;

        public Form1()

            this.northwindDataContext = new NorthwindDataContext(Properties.Settings.Default.NorthwindConnectionString);

The Death of Windows Forms?

I have been engineering software for about 4 years now. For the most part I have used Windows Forms and ASP.NET (the latter being my focus hitherto).

Presently, I have a little sideline project, that may or may not be remunerative. This ‘sideline’ will be a smart client. The principal requirements for this project are two fold.

  1. A Microsoft Outlook type interface, with a grid control that has grouping.
  2. A grid control that is similar to uTorrent, Free Download Manager or FlashGet. This grid will have an array or progress bars.

Because this project, which I’ll code name “Chronicle” is not commissioned, its is best met with free tools. At present it is in three incarnations.

  1. Using free components from I have used just the free toolkit from here
  2. Using the exceptionally good components from Devexpress
  3. Using Windows Presentation Foundation

So far the need for the project to be free has ruled out Devexpress components because they are

  1. Very expensive
  2. Add additional layers of complexity to the project. Just try to get you head around the Xtragrid, their version of the data grid view. This is not a pleasant experience, and comes at the expense of a few months to master.

The two left, are the Windows forms application with Krypton, or WPF.

I was asked this question in for forum a while ago;

What drives change in your organisation? Technology or Business requirement?

I have since struggled to answer it. Business requirement tells me that winforms is the way to go, but WPF makes things so much easier. Trying to embed controls like progress bars into data grid views requires some tricky code.

To get a faithful Outlook UI in winforms, there is the Joe Stegman sample titled Building Outlook UI in 100 lines of code with Winforms (link to the video on channel 9).

This is probably the canonical example for doing this type of thing in winforms. Only problem is that there is no grouping in the datagrid, that has been heavily modified. In WPF you just set a few properties to a Listview control.

To get a faithful Outlook UI in WPF, there is this example. Both examples lack the WOW and exact finish that Devexpress or Infragistics components have. But they teach you the principles, you can iron out your business logic, then either be creative or purchase presentation layer components.

In WPF you can add any control into any control, a huge obstacle to my project in windows forms.

In WPF to enable spell checking you do this;

<TextBox SpellCheck.IsEnabled=”True” />

In windows forms you either go with Netspell (4 years old) or this, which does not work on my PC because I’m using office 12. More tweaks required there then.

I put this question to some of the finest minds around here.