In Visual Studio, on the File menu, point to New, and then select Project.
In the Project Types list of the New Project dialog box, expand the programming language you will use and select Visual C# or Visual Basic.
In the Templates list, select Console Application.
Provide a name (such as SQLCompactEDMProject) and location for your project, and then click OK.
To generate the Entity Data Model for the Northwind.sdf, copy the Northwind.sdf from the folder %ProgramFiles%\Microsoft SQL Server Compact Edition\v3.5\Samples to the folder that your project exists.
On the Project menu, click Add new item.
In the Templates pane, select ADO.NET Entity Data Model.
Type Northwind.edmx for the model name and then click Add.
The first page of the Entity Data Model Wizard is displayed.
In the Choose Model Contents dialog box, select Generate from database. Then click Next.
Click the New Connection button.
In the Connection Properties dialog box, click the Change button in the Data Source. Select Microsoft SQL Server Compact 3.5, browse to the Northwind.sdf and then click OK.
The Choose Your Data Connection dialog box is updated with your database connection settings.
Ensure that the Save entity connection settings in App.Config as: checkbox is checked and the value is set to NorthwindEntities. Then click Next.
In the Choose Your Database Objects dialog box, clear all objects, expand Tables, and select the Customers as a table object.
Type NorthwindModel for the Model Namespace.
Click Finish to complete the wizard.
The wizard does the following:
Adds references to the System.Data.Entity.dll, System.Runtime.Serialization.dll, and System.Security.dll assemblies.
Generates the Northwind.edmx file that defines the EDM.
Creates a source code file that contains the classes that were generated based on the EDM. You can view the source code file by expanding the .edmx file in Solution Explorer.
Creates an App.Config file.
Double-click the project's application configuration file (app.config) and make sure that provider=System.Data.SqlServerCe.3.5 in the connection string.
In the code page for your application, add the following using statements:
C#:
Visual Basic:
Imports SQLCompactEDM.NorthwindModel
Note that the name of the model corresponds to the value of the namespace specified in the Northwind.edmx file.
Copy the following code example to your code file. Then, compile and run.