Local Database In Silverlight 4


In this article we will see how we can use a local DB from the project folder.

Creating Silverlight Project

Fire up Visual Studio 2010 and create a new Silverlight Business Application Project. Name it as DatabaseSample.

Let’s include a Database file to the project. As Silverlight project is the client project we cannot have the Database file there, so we should have it in Web project.

Ideally we should keep the Database file in App_Data folder, but it’s not mandatory to keep there, you can keep in other folder too.

Let’s follow the ideal situation and keep the Database file in App_Data folder.

As you see in above image, the EmployeeDB.mdf is created.

The Server Explorer would give you the Database information as shown in below image.


Let’s create a Table with the following information.



Name the Table and save it.



Let’s add some sample data to the Table from the Server explorer.


Now that we have finished configuring the Database and Table.

Let’s add a model to the project which would help us for the database operations. Yes, Entity Data Model is the right choice, let’s add one.


Add the Connection and the Entity name for the Database.


Select the table or tables that you need to operate on.


After we are done with the wizard, it would give the following model information in the designer.

Further you can proceed to perform the CRUD operation.

Hope this article is helpful.