(一).NET SubSonic2.0 的配置

1。 安装SubSonic2.03和SubSonic Tools2.03(SubSonic的官方网站http://www.subsonicproject.com/)。

2。 新建一个visual studio 2005的工程,数据库用Sql Server2000(建议用2005版本,实际上SubSonic同样支持mysql和oracle),先添加几个表。

3。 添加引用,浏览添加SubSonic.dll(SubSonic安装目录下),添加System.configuration引用。

4。 如果是Web应用程序按F5可以产生Web.config(或者手动添加,这不是什么难题),如果是WindowsForm或者Dll应用程序,手动添加App.config。在配置文件中添加:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <configSections>
      <section name="SubSonicService"
          type="SubSonic.SubSonicSection, SubSonic"
         allowDefinition="MachineToApplication"
         restartOnExternalChanges="true"
         requirePermission="false"/>
      <section name="dataConfiguration"
         type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,
         Microsoft.Practices.EnterpriseLibrary.Data" />
    </configSections>
    <appSettings/>
   <connectionStrings>
        <clear/>
        <add name="NorthwindConnection" connectionString="连接字符串"/>
     </connectionStrings>
     <SubSonicService defaultProvider="Northwind">
           <providers>
                 <clear/>
                 <add name="Northwind" type="SubSonic.SqlDataProvider, SubSonic" connectionStringName="NorthwindConnection"
      generatedNamespace="Northwind"
                 />
            </providers>
      </SubSonicService>
</configuration>

5。 VS菜单“工具-外部工具”,添加

标题:SubSonic DAL

命令:D:\SubSonic\SubSonic 2.0.3\SubCommander\sonic.exe

参数:generate /out App_Code\Generated

初始目录:$(ProjectDir)

钩选:使用输出窗口;提示输入参数;退出时关闭(推荐)

  为方便使用,在“工具-自定义”中“工具栏”新建“SubSonic”(默认钩选,显示),点“命令”-“工具”,数一下从“创建GUID”开始“SubSonic DAL”的位置即相应“外部命令某”,拖至“SubSonic”工具栏。

6。 在App_Code目录下建文件夹“Generate”,点击“SubSonic DAL”,确定即开始自动生成,完成后刷新项目即可看到生成在该文件夹下的代码。

参考:http://hi.baidu.com/wangweixp/blog/item/af54eec4a71f95ab8226acce.html

目前,Subsonic项目的使命已经完成,Linq已经成立比较成熟的方案,建议大家直接采用Linq吧

posted @ 2010-04-26 14:45  PPDev  阅读(1186)  评论(0编辑  收藏  举报