Mindscape
  • Register
  • Login
  • YOUR CART IS EMPTY
home
Software
  • Developers Toolbox
  • LightSpeed
  • Raygun
  • WPF Elements
  • Web Workbench
  • Metro Elements
  • Silverlight Elements
  • NHibernate Designer
  • Phone Elements
  • WPF Diagrams
  • Simple DB management
  • Visual Tools for SharePoint
Downloads
Store
  • Buy online
  • Purchase order
  • Volume discounts
  • Reseller
  • Software license
  • Contact sales
Blog
Support
About
  • About Us
  • Contact
  • Testimonials
rss
twitter
facebook
Creating Domain Models Objects and Databases Creating Models with the Visual Designer Creating Models in Code Creating Modifying and Deleting Entities LightSpeed Configuration Basics Validation Querying the Database Using LINQ Querying the Database Using Query Objects Transactions Working with Entities

Working with Entities

All persistent data is represented in LightSpeed as entities.  An entity represents a business object with identity.  It can be as big as a company or as small as a single order line.  Of course, an entity can have associations to other entities, allowing an aggregate to represent a rich business domain.  An entity can be loaded, modified and saved, and retains its identity throughout its lifecycle.

The Unit of Work

When you work with entities, you normally do so as part of a unit of work.  The unit of work pattern is described as:

Maintains a list of objects affected by a business transaction and coordinates the writing out of changes and the resolution of concurrency problems.

In LightSpeed, a unit of work represents a business transaction in progress.  It tracks the entities involved in that business transaction, takes care of loading entities from the database if required, and provides a way to save any changes made in the course of the business transaction.  Roughly speaking, a unit of work is a collection of entities and their pending database operations.

A unit of work is represented in LightSpeed as the IUnitOfWork interface.  IUnitOfWork provides operations to load, add and remove entities, and to save pending changes.

The basic process of working with entities in LightSpeed is therefore very simple:

·         Begin a unit of work.

·         Perform whatever combination of loads, adds, updates and removals are required for the business function you’re implementing.

·         Save any pending changes in the unit of work.

·         End the unit of work.

During this process, the unit of work object automatically:

·         Tracks loaded entities in an identity map.

·         Tracks entity state changes, so that it knows which entities if any need to be saved.

·         Updates change tracking and versioning information if required.

·         Connects to the database as and when required.

The LightSpeedContext Object

A LightSpeedContext object represents the configuration and connection settings for a particular database instance.  A LightSpeedContext is like a souped-up connection string: in addition to the physical connectivity information of the connection string, the context also specifies the database engine, mapping conventions, logging behaviour and several other options.

Most applications require only one LightSpeedContext, representing the application database and the way the application maps to that database.  Those settings won’t change over the course of the application, though they may of course be different for different instances of the application.  You’ll therefore normally create your LightSpeedContext object as a static or singleton object – there’s no benefit, and some disadvantages, to creating a new LightSpeedContext every time you need one.

Data Products

  • LightSpeed ORM
  • NHibernate Designer
  • SimpleDB Tools
  • SharePoint Tools

DevOp Tools

  • Raygun

Visual Controls

  • WPF Elements
  • WPF Diagrams
  • Silverlight Elements
  • Phone Elements

Popular Products

  • Web Workbench

    Modern web development for Visual Studio!

  • Mindscape Megapack

    All Mindscape products for one awesome price!

Quick Links

  • Forums
  • Blog
  • Register
  • Login
  • Contact us
  • Twitter
  • Facebook
  • Google+
  • YouTube
  • Linkedin
  • Rss

© Mindscape 2025. Mindscape is a registered trademark of Mindscape Limited.

  • Terms
  • Privacy