Steps to create a LINQ to SQL application using SQL Server Compact

I have listed down few steps to connect LINQ to SQL server Compact.


Make sure you have installed right version of SQL Server Compact 3.5 installed. If you need to install it, you can find the installer here:


Step 1: Create your new project within Visual Studio

It doesn’t matter if it’s a Windows Forms or WPF application. For this example, I’ll be creating a WPF application.

Step 2: Create your SQL Server Compact database. For Example: YourDatabase.sdf

You can do this by right-clicking on your Solution within the Solution Explorer and selecting "Add – New Item…" then select the "Data" category on the left and "Local Database" on the right.

Step 3: Add some Tables to the Database

You can do this within Visual Studio 2008 using the "Server Explorer". The easiest way to open up the Database within the Server Explorer is to just double click it withinthe Solution Explorer.

Also, in this example I’m just going to create a "Person" table with ID, FirstName and LastName columns.

Step 4: Create a .dbml descriptor file for the Database

To do this you need to use the SqlMetal.exe tool. Just type the following into the Visual Studio 2008 Command Prompt:

SqlMetal.exe YourDatabase.sdf /dbml:YourDatabase.dbml

By default, the SqlMetal.exe is located at drive:\Progream Files\Microsoft SDKs\Windows\vn.nn\bin.

Step 5: Add the Existing .dbml file to your project

Once you add the .dbml file, Visual Studio 2008 will automatically generate the .NET code (C# or VB.NET) for the System.Data.Linq.DataContext class that you’ll use to access your data.

Step 6: Start Coding away using LINQ to SQL!

You can now code using LINQ and your new System.Data.Linq.DataContext class against your database.


– Ananth Ramasamy Meenachi


About msarm

Aspiring Enterprise Architect.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s