SubSonic Configuration Section
Start by
adding a SubSonic configuration section inside the configuration tag in
the web.config file. This default configuration should work for most
projects.
<configSections>
<section name=“SubSonicService“ type=“SubSonic.SubSonicSection,
SubSonic“ allowDefinition=“MachineToApplication“ restartOnExternalChanges=“true“ requirePermission=“false“/>
Data Provider
Second, you will need to setup
a data provider. Three are currently supported by SubSonic: SQL
Server, MySQL and Enterprise Library. The following are sample
configurations for each of these. This information is also added inside
the configuration tag.
<SubSonicService defaultProvider=“SqlDataProvider“ >
<providers>
<add name=“SqlDataProvider“ type=“SubSonic.SqlDataProvider,SubSonic“ connectionStringName=“NorthwindConnection“/>
<add name=“ELib2DataProvider“ type=“ActionPack.ELib2DataProvider,ActionPack“ connectionStringName=“NorthwindSQL“/>
<add name=“MySqlDataProvider“ type=“ActionPack.MySqlDataProvider,ActionPack“ connectionStringName=“NorthwindMySQLConnection“/>
</providers>
</SubSonicService>
There are five values that can be set in the provider definition tag.
- defaultProvider – Multiple providers can be
setup in the configuration. This value indicates which provider to use. - fixPluralClassNames – SubSonic can remove
the plural characters from the end of table names to make class names
more consistent. For example, the Products table would produce a
Product class. - generatedNamespace – By
default all classes generated will be part of the project’s global
namespace. This value overrides that behavior and includes all classes
in the given namespace. For example, by setting this to Northwind you
would get Northwind.Product. - spClassName –
Each stored procedure will generate a method of the same name. The
value will be the class these methods are included under. For example,
by setting this to SPs the CustOrderHist stored procedure would be
SPs.CustOrderHist. Using the above namespace example in conjunction
with this value would produce Northwind.SPs.CustOrderHist. - templateDirectory
– It is possible to override the code generated by SubSonic. This
directory would contain the code templates to override the default
templates supplied. This will be covered in greater detail later when
discussing code generation. - useSPs – If you
do not want a class generated for stored procedures, set this value to
false.
Database Connection String
Third,
you need to define a database connection string.
<connectionStrings>
<add name=“NorthwindConnection“ connectionString=“Data Source=localhostSQLExpress;Database=Northwind; Integrated Security=true;“/>
</connectionStrings>
Build
Provider Configuration
Fourth, you need to setup a
build provider to create the auto generated classes. This needs to be
added to the compilation tag.
<buildProviders>
<add extension=“.abp“ type=“SubSonic.BuildProvider,SubSonic“/>
</buildProviders>
Build
Provider Definition
Last, you need to create an .abp
file for this build provider to use. You do this by adding a text file
named Builder.abp to the App_Code folder. Inside this file you indicate
which database tables should have auto generate classes. If you want
all tables, just enter *, otherwise, list the tables one per line.
Jabbaarrr..