Local Database in Silverlight 4


Introduction

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.

1.gif
 
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.

2.gif
 
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.
 
3.gif

Let's create a Table with the following information.
 
4.gif

5.gif 

Name the Table and save it. 

6.gif 

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

7.gif
 
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.

8.gif 

Add the Connection and the Entity name for the Database.
 
9.gif 

10.gif

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

11.gif 

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

12.gif
 
Further you can proceed to perform the CRUD operation.

Hope this article is helpful.

Up Next
    Ebook Download
    View all
    Learn
    View all