Scott Kuhl

You Will Be Assimilated

  Home  |   Contact  |   Syndication    |   Login
  751 Posts | 1 Stories | 558 Comments | 362 Trackbacks

News


Search My Blog

Search GWB



Help CMTA!

Twitter












Tag Cloud


Archives

Post Categories

Image Galleries

My Sites

SubSonic requires a minimal amount of configuration to get going. 

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"/>

</configSections>

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" spClassName="SPs" fixPluralClassNames="true">

<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 SubSonicService 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=localhost\SQLExpress; 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.

Summary

In summary, these are the items you need to configure.

  • SubSonic Configuration Section
  • Data Provider
  • Database Connection String
  • Build Provider Configuration
  • Build Provider Definition

Here is a sample web.config with all the SubSonic required values defined.  You can also use the web.config included in the sample web site downloaded along with the SubSonic source code as a starting point, which is where these sample values are derived from.

<?xml version="1.0"?>

<configuration>

<configSections>

<section name="SubSonicService" type="SubSonic.SubSonicSection, SubSonic" allowDefinition="MachineToApplication" restartOnExternalChanges="true" requirePermission="false"/>

</configSections>

<appSettings/>

<connectionStrings>

<add name="NorthwindConnection" connectionString="Data Source=localhost\SQLExpress; Database=Northwind; Integrated Security=true;"/>

</connectionStrings>

<SubSonicService defaultProvider="SqlDataProvider" spClassName="SPs" fixPluralClassNames="true">

<providers>

<add name="SqlDataProvider" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="NorthwindConnection"/>

</providers>

</SubSonicService>

<system.web>

<compilation debug="true" defaultLanguage="C#">

<buildProviders>

<add extension=".abp" type="SubSonic.BuildProvider, SubSonic"/>

</buildProviders>

<assemblies>

<add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="System.Data.OracleClient, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>

<add assembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>

<add assembly="MySql.Data, Version=1.0.7.30072, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/></assemblies></compilation>

<authentication mode="Windows"/>

</system.web>

</configuration>

To make sure everything is working, build the web site, then open up the Class View window and you should see class names that match your tables.  For example, using the Northwind database, you should now see classes named Category, Customer and Employee.

Find the entire series of posts here.

posted on Friday, November 17, 2006 4:57 PM

Feedback

# Problem with web.config 9/18/2007 6:30 AM Fabian
Warning 1 The 'requirePermission' attribute is not declared. D:\WebSite\NetTicket\Web.config 4 148 D:\WebSite\NetTicket\


# re: Getting Started with SubSonic - Part 4, Configuration 3/11/2008 8:43 PM Vincent Luo
very good

# re: Getting Started with SubSonic - Part 4, Configuration 6/28/2008 4:21 AM Shakeel
Can you please let me know, how to configure SubSonic with .Net 1.0. I've been using it successfuly with .Net 2.0.

The specific problem i'm facing is that, using .Net 1.0, the <connectionStrings /> tag is not recognized in web.config. And <SubSonicService /> tag requires the parameter connectionStringName as must.

So my question is;

-?- Is there any way to specify connectionString directly to <SubSonicService /> instead of specifying connectionStringName?

Or other wise how to setup web.config settings while using SubSonicService with ASP.Net 1.0

Thanks and regards.

# re: Getting Started with SubSonic - Part 4, Configuration 9/1/2008 8:04 AM nafser33
it is a good one. this web.cofig file is built successfully but it is not generating class for the tables...how can i solve this problem.please mail me in nafser33@gmail.com

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 5 and 2 and type the answer here: