代码改变世界

[CODE Smith]SchemaExplorer中对象的扩展属性

2008-02-20 13:10  Jaypei  阅读(373)  评论(0编辑  收藏  举报

CodeSmith定义的扩展属性包括table columns, view columns, 和 command parameters。

如:SQL Server定义了一个扩展属性来标识表中的唯一标识字

Identity Field = <%
foreach(ColumnSchema cs in SourceTable.Columns) {
    
if(((bool)cs.ExtendedProperties["CS_IsIdentity"].Value)==true)
    {
        Response.Write(cs.Name);
    }
}
%>

输出默认值:
foreach(ColumnSchema cs in SourceTable.Columns)
{
    
if(cs.ExtendedProperties["CS_Default"!= null)
    {
        Response.WriteLine(
"{0,-11} : {1}",cs.Name,cs.ExtendedProperties["CS_Default"].Value);
    }
}


其他扩展属性:

  • Table columns
    CS_IsRowGuidColCS_IsIdentityCS_IsComputed 、 CS_IsDeterministicCS_IdentitySeedCS_IdentityIncrementCS_Default
  • view columns
    CS_IsComputedCS_IsDeterministic
  • command parameters
    CS_Default

另外,每个对象都有一个CS_Description的扩展属性。你也可以通过SQL Server中的系统存储过程sp_addextendedproperty来创建自定义的扩展属性。例如:我们执行如下命令为Customer这张表的ID字段添加一个Caption的扩展属性:

sp_addextendedproperty 'caption''Customer ID''user', dbo, 'table', Customers,'column', id

在数据库中执行完这条语句后,CodeSmith 中将会在这个字段的扩展属性集合中加上Caption属性。

参考TerryLee的《CodeSmith开发资料.pdf》