Skip to end of metadata
Go to start of metadata

This page provides in-depth guidance to create apps that use SQLite as its local data storage using Crosslight Business Template. You will learn how to configure SQLite for the first-time, setting up the domain model through Intersoft Entity Designer, and add some simple settings and code to enable the SQLite.

If you haven't familiar with Crosslight Business Template, please check out Business Template. Once you're able to run the project and login to the app, notice that Page 3 in the navigation drawer will display the list of items, as well as features for add, edit and delete the item. By default, the business template retrieves the items data from WebApi. This page guides you how to change the data storage from WebApi to local storage using SQLite.

On this page:

Configure Project References to Enable SQLite

To use Crosslight SQLite in your project, you need to configure the required references. To do this, simply use the NuGet extension for Mac or Visual Studio and install the Intersoft.Crosslight.Data.Sqlite package.


To learn more on how to use Crosslight NuGet Packages, see Introduction to Crosslight NuGet Packages.

After following this steps, your project should look like this:

Configure Entity Model (EDMX)

The Entity Model (EDMX) is an XML file that represents the list of entities and the relationship of every entity. To learn how to generate an entity model from a database, please refer to Creating Entity Model and Services with Crosslight Entity Designer Extensions

Follow the steps below to configure the entity model:

  1. Open the EMDX file in the DomainModels project, right click at the empty space in diagram then select properties and change DevForceEnabled to false. This step is only needed if you have other third party entity tools installed such as DevForce.
  2. Select all your entities in the diagram, right click then select properties and change RepositoryType to EditableLocalEntityRepository.

By simply changing the repository type, the app will now store and load the data from local storage using SQLite.

Configure AppService.cs

Some configuration needed in AppSercive.cs are:

  1. Define LocalDatabaseName and LocalDatabaseLocation in AppSettings.

    AppService.cs - Constructor
  2. Add SQLite service to ServiceProvider.

    AppService.cs - Constructor
  3. Create the tables for the models, and insert some predefined data.

    Appservice.cs - Onstart Method

Disable Login and Synchronization (Optional)

Since the sample demonstrates how to use create an apps that use Local Storage, the app will not use synchronization, and most likely doesn't need login process. To skip the login process created by Crosslight Business Template, you can set the default RootViewModel to DrawerViewModel. To do this, simply change this.SetRootViewModel<HomeViewModel>() to this.SetRootViewModel<DrawerViewModel>() even if this.AccountService.IsLoggedIn() return false in AppService.OnStart method.

In addition, if the account and synchronization services aren't required, you can comment all the lines in the Navigated method of DrawerViewModel class, except base.Navigated(parameter).


The sample code for this article can be downloaded from our Git server: