SubSonic指南中文版
翻译:王鹏程张原王伟
策划:毛凌志
2009年1月
北京工业大学软件学院
PS:有问题反馈至
Getting Started with SubSonic
By Scott Kuhl (kswithblogs/scottkuhl)
SubSonic is an open-source toolt, created by Rob Conery, as an attempt to put the fun back into programming and just get the job done. Inspired by Ruby on Rails, SubSonic takes a minimalist approach to coding and emphasizes convention over configuration. While it takes its inspiration from Ruby on Rails, it is not a port of it. (Check out MonoRail it that's what you're looking for.) Instead, Su
bSonic takes the best ideas of Ruby on Rails and adapts them into the already existing ASP framework. Currently SubSonic, version 1.05, implements two core features:
SubSonic是一种开源工具,由Rob Conery创造,作为一种尝试把乐趣带入计划并且完成这项工作。灵感来自Ruby on Rails,SubSonic采取了最低限度的办法,编码,并且强调结构上的惯例。虽然它的灵感来自Ruby on Rails,但是这并不是它的一种端口。(查看单轨这是您要找的内容。)相反,SubSonic继承了Ruby on Rails最好的思想,并且使它们融入已经现有的ASP框架。目前,1.05版本SubSonic有两个核心特点:
ActiveRecord
This design pattern in its simplest form is one class per databa table, one object per databa row. SubSonic includes a build-time code generator to implement this pattern that acts as an object-relational mapper eliminating the need to write SQL. It also includes a dynamic query tool and simple store procedure support to extend the model when needed.
这种设计模式的最简单的形式是每个数据库表一类,每个数据库行一个对象。SubSonic 包括建立时间码发生器实施这一模式,作为一个对象关系映射无需编写SQL。它还包括一个动态查询工具和简单的存储过程支持在需要时扩展该模型。
Scaffolding
Admin pages are a chore that scaffolding helps remove. Simply point a scaffold control at a table and you get the standard grid view and detail view to find and update data in the underlying table. While not meant to ever be shown to urs, it makes a nice, quick and easy developer tool.
管理的网页是件scaffolding帮助删除的苦差事。只要在表格中指点棚架控制,你得到标准的网格视图和细节视图,用来在潜在的表格中找到并更新数据。虽然并不意味着永远向用户显示,但它提出了好的、快速简便的开发工具。
爱是一种选择
Requirements 需求
SubSonic will work fine with Visual Web Developer 2005 Express Edition and SQL Server 2005 Express Edition, so you can get started without dropping a dime. You can also u MySQL or any databa that can be accesd through Enterpri Library for Framework 2.0, but SQL Server is probably the most likely tup. Note: The sample web site included with the SubSonic source code includes an SQL script to create the Northwind databa. This article will u that databa when examples are needed. SubSonic可以与Visual Web Developer 2005 Express Edition和SQL Server 2005 Express Edition很好的工作,这样你就可以未留任何遗漏的使用。您也可以将MySQL或
任何Enterpri Library可读取的数据库用于 Framework 2.0,但SQL Server的也许是最有可能的安装。注:样本的网站包括SubSonic的源代码包含一个SQL脚本创建Northwind数据库。本文在例子需要时将使用该数据库。
Setup 安装
98年是什么命
Setup is easy, just download SubSonic from CodePlex and reference SubSonic.dll found in the bin directory. Alternatively, you can open the solution and compile a relea build yourlf.
(You will need Visual Studio 2005 Standard Edition to open the solution becau it also includes a sample web site or you can u Visual C# 2005 Express Edition to open just the project.)
安装非常简单,只需从CodePlex下载SubSonic并参考SubSonic.dll在bin路径中建立。另外,您也可以打开解决方案,并自己新建一个。
(您需要的Visual Studio 2005标准版开来打开解决方案,因为它也包括一个范例网站或您可以使用Visual C# 2005 Express Edition仅仅来打来项目。)
Configuration 配置
SubSonic requires a minimal amount of configuration to get going.
有关爱的故事
SubSonic的使用要求一个最低的配置数量。
SubSonic Configuration Section SubSonic配置节
Start by adding a SubSonic configuration ction inside the configuration tag in fig file. This default configuration should work for most projects.
首先,在fig文件中,在<configSections>内增加一个SubSonic配置节。这种默认配置应该对大多数项目有用。
<configSections>
炒西兰花的家常做法
<ction name="SubSonicService" type="SubSonic.SubSonicSection, SubSonic"
allowDefinition="MachineToApplication" restartOnExternalChanges="true"
requirePermission="fal"/>
</configSections>
Data Provider 数据供给者
Second, you will need to tup a data provider. Three are currently supported by SubSonic: SQL Server, MySQL and Enterpri Library. The following are sample configurations for each of the. This information is also added inside the configuration tag.
第二,您将需要设置一个数据提供者。目前被SubSonic支持的有三个:SQL Server,MySQL和Enterpri Library。下面是这三个的示例配置。这些信息也添加在
<configSections>内。最刺激的一次
<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 t in the SubSonicService tag.
在<SubSonicService>内有五个值可以设置。
ŸdefaultProvider - Multiple providers can be tup in the configuration. This value indicates which provider to u.
n多个供应者可以在配置内设置。这个值表示使用的是哪个供应者。
Ÿ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.
n SubSonic可以从表名末尾删除复数字符,以使类别名一致。例如,产品表会显示产品类别。
ŸgeneratedNamespace - By default all class generated will be part of the project's global namespace. This value overrides that behavior and includes all class in the given namespace. For example, by tting this to Northwind you would get Northwind.Product.
n默认情况下产生的所有类别将是该项目的全局命名空间的一部分。这个值忽略那种行为,并且在特定的命名空间包含所有类别。例如,通过设置这值为
Northwind你会获得Northwind.Product 。
ŸspClassName - Each stored procedure will generate a method of the same name. The value will be the class the methods are included under. For
example, by tting 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.
n每个存储过程会产生相同名称的一种方法。这个值是将这些方法包含在其中的类。例如,通过设置这值为SPs,CustOrderHist存储过程将会成为
SPs.CustOrderHist 。使用上述命名空间例子与这个值相结合将会产生
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 Templates.
n有可能覆盖SubSonic产生的代码。此目录将包含的代码模板,以取代默认模板提供的。这将会在稍后讨论代码生成模板时更详细地讲解。
ŸuSPs - If you do not want a class generated for stored procedures, t this value to fal.ps虚化
n如果你不想要一个为存储程序而产生的类,设置此值为fal。
Databa Connection String 数据库连接字符串
Third, you need to define a databa connection string.
第三,你需要定义一个数据库连接字符串。
<connectionStrings>
<add name="NorthwindConnection" connectionString="Data荷兰郁金香
Source=localhost\SQLExpress; Databa=Northwind; Integrated Security=true;"/> </connectionStrings>
Build Provider Configuration 建立供应商配置
Fourth, you need to tup a build provider to create the auto generated class. This needs to be added to the compilation tag.
第四,你需要设置一个建立供应商来产生自动生成的类。这需要在<compilation>内添加。
<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 u. You do this by adding a text file na
med Builder.abp to the App_Code folder. Inside this file you indicate which databa tables should have auto generate class. If you want all tables, just enter *, otherwi, list the tables one per line.
最后,您需要创建一个.abp文件供此建立供应商使用。通过在App_Code文件夹中增加一个命名为Builder.abp的文本文件来这样做。在这个文件中你说明哪些数据库表应该有自动生成类。如果你想所有表格,只需输入*,否则,每行一个的列出各个表。
Summary 总结