Configuration
EntitySpaces allows for both configuration file based settings or configless setup.
We are going to look at using a configuration file first. This is a sample app.config
file.
Example Web/App config
The first part in the configSections merely registers the ConfigurationSection class
that reads the EntitySpaces section down below. It is the EntitySpaces section that
we are interested in. Let’s look at the setup. First, we have the connectionInfo
element with the default set to “SQL”. The default specified must match the “name”
of one of your connections. You can register any number of connections in the connection
section. This config file only registers a single connection. Connections are registered
via the add element.
- The name is merely a nickname that you can reference the connection by in code if
needed. You can “name” them anything you like, but each one must
have a unique “name”.
- The providerMetadataKey tells EntitySpaces which MetadataMap to use. This will always
be “esDefault” for any classes generated using the Generated Master template, regardless
of the back-end database. (Note: Only change this when working with multiple databases
providers such as Microsoft SQL Server and MySQL within the same application, and generating
for one of them with the MetadataMap template.
- The sqlAccessType is either “DynamicSQL” or “StoredProcedure”. This governs your
CRUD operations CREATE/READ/UPDATE/DELETE.
- The provider indicates which EntitySpaces data provider you want to use with this
connection.
- The providerClass is where you indicate whether you want to run with Distributed
Transactions or ADO.NET connection based transactions. You use “DataProvider” for
ADO.NET connections and “DataProviderEnterprise” for COM+ distributed transactions.
Most of the time you will use “DataProvider”.
- The connectionString is the connection string for your database. Be careful if you
copy the connection string from the EntitySpaces code generator Settings.
At runtime, EntitySpaces does not use OLEDB, it uses an ADO.NET connection string.
For example, you would need to delete "Provider=SQLOLEDB.1;".
- The databaseVersion is used only for SQL Server currently. If you are using SQL Server
2005 or higher, you need to specify "2005" in order for timestamps to be handled correctly.
(Note: Do not use "2008" for SQL Server 2008. Use "2005".)
Programattic Configuration
EntitySpaces also allows for configless execution. That is, no .config file required.
You can do it all in code. In fact, certain environments such as SQL CE and DotNetNuke
really need this feature. Below we are registering the same settings that are possible
in an app.config or web.config file. Note that you only need to do this once for
the life of your application. You must remove all EntitySpaces sections from the
app/web .config file to use configless execution. You cannot use both.
C#
VB