Getting started with Mindscape LightSpeed

In the weekend I was reworking a prototype of something I’m working on and I wanted to use LightSpeed to manage the data access and thought it would be appropriate as a code example of how to quickly and easily get started with LightSpeed. To clarify, I only needed LightSpeed for the persistence mechanism as opposed to the full domain modeling capability at this stage of my project.

The Problem
My application needed a mechanism for persisting configuration. The configuration this application stores is extensible and ideally will be extended by 3rd party plug-ins which means I needed to expose a service that can be used by these 3rd parties to store their custom configuration in a manner that will give access both to their plug-in as well as our application.

I’m also a staunch hater of >300KB XML configuration files and it’s early days in the prototype :)

Step 1: Create your model classes
I have a simple configuration entity that I wanted to be able to persist to a SQLite database (LightSpeed supports many different database engines by the way). At this stage of my prototype I’m effectively only storing a key/value pair, a human readable name and description and a type (e.g. string, color, int). In this code example you will need to reference LightSpeed in your project to gain access to the Entity<> class that we are inheriting off.

Note that LightSpeed takes care of the enum as well and will happily convert it to an int at the database level :) Too easy.

using System;
using Mindscape.LightSpeed;
namespace Mindscape.Carbon.Core.Configuration
  public class ConfigurationItem: Entity<guid>
    public enum ConfigValueType
    private string _referenceName;
    private string _value;
    private ConfigValueType _valueType;
    private string _displayName;
    private string _description;
    public string ReferenceName
      get { return _referenceName; }
      set { Set(ref _referenceName, value, "ReferenceName"); }
    public string Value
      get { return _value; }
      set { Set(ref _value, value, "Value"); }
    public ConfigValueType ValueType
      get { return _valueType; }
      set { Set(ref _valueType, value, "ValueType"); }
    public string DisplayName
      get { return _displayName; }
      set { Set(ref _displayName, value, "DisplayName"); }
    public string Description
      get { return _description; }
      set { Set(ref _description, value, "Description"); }

Step 2: Create your database
Currently you create your database manually however we are working on tools to do this for you. Note that I’m using a GUID as the primary key on this table and we didn’t need to add it to the model object in the previous step, LightSpeed does this for you. You only need to supply the primary key type in Entity. Now you can jump into whatever database you’re working with and create the table.

In my case I was using SQLite and just used a simple create table command:

CREATE TABLE ConfigurationItem(
  Id                GUID            NOT NULL PRIMARY KEY,
  ReferenceName     NVARCHAR(50)    NOT NULL UNIQUE,
  VALUE             NVARCHAR(100)   NOT NULL,
  ValueType         INT             NOT NULL,
  DisplayName       NVARCHAR(100)   NOT NULL,
  Description       NVARCHAR(1024)  NOT NULL);

Step 3: Add LightSpeed to your configuration
We need to tell our application about the database that LightSpeed should be working with and we can do this in code or in the .config file for our project. In this example I’ve elected to put it into the app.config of my project.

    <section name="LightSpeed" 
        type="Mindscape.LightSpeed.Configuration.LightSpeedConfigurationSection, Mindscape.LightSpeed" />
    <add name="ConfigDB" connectionString="Data Source=MyDatabase.db3"/>
  <LightSpeed dataProvider="SQLite3"

Step 4: Work with your data
That’s it! All the configuration work has been completed and there is no heavy XML mapping file or complex setup to tell LightSpeed about the database. The whole philosophy behind LightSpeed is to help developers get work done quickly and I hope this example and your own work with LightSpeed proves that. In following posts I will provide detail about working with your data however here is a taster of how easy it is to now put new objects into the database:

    ConfigurationItem item = new ConfigurationItem();
    item.ReferenceName = "MyRefName";
    item.ValueType = ConfigurationItem.ConfigValueType.STRING;
    item.DisplayName = "Example Config";
    item.Description = "This is an example configuration key";
    item.Value = "example";

In this example I had an extremely simple model however you can appreciate that there is significantly less leg work required to get a LightSpeed solution up and running. I will post more advanced real world examples to help you gain more from working with LightSpeed in the near future. Also please leave any comments or questions you have on my blog regarding LightSpeed.

How can you use LightSpeed?
We currently are in late beta with an RTM of LightSpeed just around the corner. You can grab the download of LightSpeed from the Mindscape EAP site. You can also post in the forums to discuss any challenges that you have or to ask questions. We welcome any feedback.

Hope that helps,

– JD

Tagged as LightSpeed

7 Responses to “Getting started with Mindscape LightSpeed”

  • Hey Guys.

    Nice product, not sure if it would do what we want, as we want to run on .net CF and full framework and use SqlCE and Sql 2005 as our associated Data Stores. Our objects would also need to gather data from at least 2 tables in the tables and i believe your product only does 1 -> 1 object -> table type mappings? Anyways i’m interested to know how long you have been working on the product, and what sort of resource and energy has gone into it? Trying to convince management that we are best to buy rather than build :) based on certain timeframes.


  • Hi Greg,

    Cheers for taking a look. A couple of questions:

    – Have you had a look at SQLite for your mobile scenario? The main reason we don’t support CE at this stage is due to it’s lack of support for batching which is required to use eager loaded associations. That’s not to say we can’t support it.

    – Can you tell me a little bit about your two table scenario?

    I would strongly advise against building your own solution :-) If LightSpeed doesn’t fit in this case I would recommend taking a look at Base4.Net from Alex James.



  • Hi Andrew

    Thanks for the quick reply. We have not yet looked into SQLite.

    As for the two table scenario we have the following.

    JobBaseData Table, made up of a JobID, JobState, and other fields.
    JobSubClassData Table JobID (FK to Job Base ), and other subclass fields

    The two tables linked together describe a Job in our System.

    We may have say 2 different JobSubClass Tables, each one storing specific data for that particular JobType. ( we would create 2 objects JobType1 and JobType2 to represent the job data, both objects would derive from a Job Base object) .. Jobs are also Hierarchical, and a child job could have multiple parents ( Many To 1 Relationship ) ( not that a parent might be another job, or could be say a Customer or some other object )

    Would this be possible in your system? How long has Lightspeed been in development?


  • Hi Greg,

    What your describing sounds like an inheritance mapping scenario. Basically, when you want to map an inheritance structure to the database. There are three common patterns for implementing this: Single Table Inheritance, Class table inheritance and Concrete Table Inheritance. See here for a bit more detail on these patterns:

    We currently only support Single Table Inheritance (mapping an inheritance hierarchy to a single table) because it is simple and has the best performance. Personally, I would be hesitant about using a multi-table strategy because I don’t believe it buys you much apart from perhaps saving a small amount of disk space.

    With respect to associations, an Entity may have an arbitrary number of one-to-many or many-to-one associations, including self-referencing hierarchies. So a Job could have a collection of child jobs as well as a parent Job and an associated Customer.

    LightSpeed has been in development for about 5 months and we are planning on releasing our first v1 release candidate this Friday.



  • Hiya, a newbie from D&I Intergen wlg here.

    My limited understanding of LightSpeed, essentially it’s an O/RM technology… so apart from the plumbing code that most of the O/RM products out there are able to hide away, what is it that LightSpeed stands out comparing to others like from alex.

    Whenever I see table field names hardcoded in a class, my hands start to sweat. With my very limited experience with O/RMs, they are not very resilient db schema changes. Say if I went ahead and changed “ReferenceName” in the database directly. The above code wouldn’t be able to pick it up at compile time, could it? and I guess It will throw an exception or something sort in runtime if I’m to temper with the data in that field? From that assumption, I’ll have to change this hardcoded string to whatever I’ve renamed the field name to.

    I am just thinking out loud here without doing much research on any solutions to this problem. Is it possible to design an O/RM in a way that, this data access layer/project that’s based on an O/RM, at compile time, is able to pick up the table name and fields from the respective metadata tables and code-gen these business enitity classes i.e. ConfigurationItem in this case? Then, if any existing business logic code that’s written against these business entity classes will fail during compile time rather than runtime which I would have had in your example?

  • Hi Sun,

    LightSpeed combines traditional O/R Mapping with support for building .NET domain models (validation, data-binding etc.) It differs from other frameworks primarily in philosophy. Basically, convention over configuration (RoR style) so that if you are trying to solve the 95% case then you can move as quickly as possible. The framework is small and fast: a single 120KB dll that performs twice as fast as NHibernate (2MB worth of dlls) on our internal benchmarks. One of our internal mantras for LightSpeed is: “The utorrent of O/R Mapping.” :-) Another prime focus is usability – we have tried to make the API as intuitive as possible. It uses patterns from Domain-Driven Design such as Repository, Unit of Work and Specification.

    The problem of changing the database schema underneath your data access layer occurs irrespective of whether you are using an O/RM. As you point out you can use code generation to generate your domain model classes off of your database schema and LightSpeed is good candidate for code generation. However, beware that code generation can have a significant negative impact on your day-to-day build process – i.e. It will slow you down.

    The real solution to the problem is actually quite simple: Write unit tests. You do write tests don’t you? :-)



  • Hi Andrew,

    Thanks for the reply. I’m downloading the beta release and gonna have a play around with it.

    Unit tests? what are those, never heard of them :P



  • Leave a Reply


Join our mailer

You should join our newsletter! Sent monthly:

Back to Top