Silverlight Database

The Silverlight library in this article extends RIA service entities and provides save & load method to save/load entities directly into application storage (Isolation storage). The library supports dynamic quota management for application storage i.e. if an entity requires more space to store it will prompt user to confirm new size of quota store. The saving and loading supports asynchronous processing of entities with inbuilt compression which allows your application to provide non blocking UI. Library can be used to build online-offline mode based Silverlight applications without additional programming overheads.

Code to save RIA Entities in the storage space

EmployeeContext context = new EmployeeContext();
dataGrid.ItemSource = context.Employees;
Action<LoadOperation<Patient>> completeProcessing = delegate(LoadOperation<Patient> loadOp)
{
    if (!loadOp.HasError)
        {
            loadOp.Entities.Save();
        }
        else
        {
            LogAndNotify(loadOp.Error);
            loadOp.MarkErrorAsHandled();
        }
};
context.Load(context.GetEmployeesQuery(), completeProcessing, null);

Code to load RIA Entities from storage space

EmployeeContext context = new EmployeeContext();
context.Employees.Load();

You can also use the same library to save and load genric data you need to provide the filename to which the object set is saved whereas with Ria EntitySet the fileName is optional which is calculated based on the data type of entity.
Code to save List<string> into storge sapce

List<string> names = new List<string>();
names.Add("Employee1");
names.Add("Employee2");
names.Add("Employee3");
names.Save("Employee4");
names.Save("EmployeeesDataSet");

Code to load List<string> into storge sapce

List<string> names = new List<string>();
names.Load("EmployeeesDataSet")

Note: The Load method supports Asynchronous (default) and Synchronous operation where as Save method only supports Asynchronous operation.You can also override the Quota Management screen globally in your application and if not overrided the library will use in-built screen shown below (right image).

How it works : diagram is self explanatory..

Source code is now available here, Because of time constriants i was not able to comlete the code behind for the isolation storage screen above, however the library is now completed and published with silverlight unit test project.

2 thoughts on “Silverlight Database

  1. Hi Rajneesh,
    Is it possible to call EntitySet.Save() method instead of SubmitChanges and call SubmitChanges at later stage (after calling EntitySet.Load()) say when Internet connection is available or user click on sync button ?
    Thanks

    Like

  2. Yes, The library saved the state of objects in collection and attach the entity object back to the collection with original state.The idea of import/export RIA entites was initially developed by ColinBlair (WCF RIA Contrib project) on codeplex.

    Like

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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