LightSpeed Configuration Basics
As described above, the LightSpeedContext object contains the configuration and connection settings for a particular database instance. The usual way to store these settings is in the application configuration file – web.config for Web applications and sites, appname.exe.config for desktop applications – though you can also set them in code. LightSpeedContext supports a lot of configuration options, which we describe more fully in the relevant sections of this user guide, and summarise in the Appendices. In this section, we’ll describe the minimal configuration for connecting to a database.
LightSpeed Configuration Section
When you store settings in the application configuration file, you must declare and implement a lightSpeedContexts section, and define your specific settings within that section using the add element, as follows:
Declaring the lightSpeedContexts section |
<configSections> |
Implementing the lightSpeedContexts section |
<lightSpeedContexts> |
Loading a LightSpeedContext from Configuration
To load a LightSpeedContext from configuration, pass the name of the configuration file entry to the LightSpeedContext constructor:
Loading a LightSpeedContext from configuration |
private static readonly LightSpeedContext _context = new LightSpeedContext("Test"); |
Specifying the Data Provider
LightSpeed needs to know what kind of database you are using. Specify this using the dataProvider attribute:
Specifying the data provider |
<lightSpeedContexts> |
The following values are recognised for dataProvider:
Provider Name | Description |
SqlServer2000 | Microsoft SQL Server 2000 using System.Data provider. |
SqlServer2005 | Microsoft SQL Server 2005 using System.Data provider. |
SqlServer2008 | Microsoft SQL Server 2008 using System.Data provider. |
MySql5 | MySQL 5 database using MySql.Data provider. |
PostgreSql8 | PostgreSQL 8 (or higher) database through Npgsql provider. |
SQLite3 | SQLite 3 database through System.Data.SQLite provider. |
Oracle9 | Oracle 9 (or higher) database through System.Data.OracleClient provider. |
Oracle9Odp | Oracle 9 (or higher) database through Oracle.DataAccess provider. |
VistaDB3 | VistaDB 3 database through VistaDB.NET20 provider. This provider has been deprecated and is no longer officially supported. |
VistaDB4 | VistaDB 4 database through VistaDB.4 provider. |
SqlServerCE | SQL Server Compact 3.5 through System.Data provider. |
SqlServerCE4 | SQL Server Compact 4 through System.Data provider (requires additional supporting assembly – see Working with Database Providers chapter). |
DB2 | DB2 9.5 through IBM.DB2 provider. |
AmazonSimpleDB | Amazon SimpleDB cloud database or compatible. |
The default provider is SqlServer2005 (Microsoft SQL Server 2005).
Specifying the Connection String
Connection strings are stored in the <connectionStrings> element as per the standard .NET configuration file schema. When configuring LightSpeed you can refer to a connection string by name using the connectionStringName attribute:
Specifying the connection string |
<lightSpeedContexts> |
Other Configuration Options
Other common configuration options include:
· pluralizeTableNames
· identityMethod
· quoteIdentifiers
See the chapter Controlling the Database Mapping for more information on these options.