2.2引入类库
using Microsoft.Data.Schema.Extensibility; using Microsoft.Data.Schema.SchemaModel; using Microsoft.Data.Schema.SchemaModel.Abstract; using Microsoft.Data.Schema.ScriptDom.Sql; using Microsoft.Data.Schema.Sql.SchemaModel.SqlServer; using Microsoft.Data.Schema.Sql.SqlDsp; using Microsoft.Data.Schema.StaticCodeAnalysis;
2.3定义类

定义了一些类的属性(attributes)。
DatabaseSchemaProviderCompatibility允许用户指定Sql Rule所要应用的SqlDatabase类型,这里使用的是标准SqlDatabase。
DataRuleAttirbute用来指定name, id, description等其他规则属性。
SupportedElementTypeAttribute,此属性用来指定要验证的数据库对象,此处要验证的是表字段。
2.4构造函数
定义一些列的命名规则,即4个字母的表名_字段名。
public MyStylePrefixedTable() : base( "SqlRule", "DD0002", "All columns must be in form xxxx_xxxxxxxx", "All columns must be in form xxxx_xxxxxxxx where the part befor the _ is table code, and part after is descriptivename", "", "MyStylePrefixedTable") { }
2.5新建资源文件

所有传到DataRuleAttribute里面的字符串都需要添加到以上资源文件中。填写资源文件如下图:

出处:灵动生活
责任编辑:bluehearts
上一页 VS2010中创建自定义SQL Rule [1] 下一页 VS2010中创建自定义SQL Rule [3]
◎进入论坛网络编程版块参加讨论
|