CodeSmith实用技巧(四):使用扩展属性

SchemaExplorer 允许我们获取数据库中一些对象的信息。如果你使用的是 SQL Server2000 数据库,你可以通过扩展属性获取很多对象的有用的信息。例如: SQL Server 定义了一个扩展属性来标识表中的唯一标识字段,在模版中可以这样写: <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

ExpandedBlockStart.gif ContractedBlock.gif Identity Field  =   <%   foreach (ColumnSchema cs  in  SourceTable.Columns)  dot.gif
InBlock.gif      
if( ((bool)cs.ExtendedProperties["CS_IsIdentity"].Value) == true)
ExpandedSubBlockStart.gifContractedSubBlock.gif      
dot.gif{
InBlock.gif            Response.Write(cs.Name);
ExpandedSubBlockEnd.gif      }

ExpandedBlockEnd.gif}

None.gif
%>

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

Table columns

None.gif  CS_IsRowGuidCol
None.gif
None.gif CS_IsIdentity
None.gif
None.gif CS_IsComputed
None.gif
None.gif CS_IsDeterministic
None.gif
None.gif CS_IdentitySeed
None.gif
None.gif CS_IdentityIncrement
None.gif
None.gif CS_Default

view columns

None.gif  CS_IsComputed
None.gif
None.gif CS_IsDeterministic

 command parameters

None.gif  CS_Default

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

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

在数据库中执行完这条语句后,CodeSmith中将会在这个字段的扩展属性集合中加上Caption属性。有关SQL Server 中的扩展属性的内容请参考联机丛书。

转载于:https://www.cnblogs.com/wayne-ivan/archive/2007/06/15/784403.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值