1
<%
@ CodeTemplate Language
=
"
C#
"
TargetLanguage
=
"
T-SQL
"
Src
=
""
Inherits
=
""
Debug
=
"
False
"
Description
=
"
Template description here.
"
%>
2 <% @ Property Name = " SourceTable " Type = " SchemaExplorer.TableSchema " Description = " ????-??. " %>
3 <% @ Assembly Name = " SchemaExplorer " %>
4 <% @ Import Namespace = " SchemaExplorer " %>
5 < script runat = " template " >
6 public string getParameter(ColumnSchema col)
7 {
8 String parameter = " @ " + col.Name + " " + col.NativeType;
9 switch (col.DataType)
10 {
11 case DbType.Decimal:
12 {
13 parameter += " ( " + col.Precision + " , " + col.Scale + " ) " ;
14 break ;
15 }
16 default :
17 {
18 if (col.Size > 0 )
19 {
20 parameter += " ( " + col.Size + " ) " ;
21 }
22 break ;
23 }
24 }
25 return parameter;
26 }
27 </ script >
28 create procedure dbo.Delete <%= SourceTable.Name %>
29 <% for ( int i = 0 ;i < SourceTable.PrimaryKey.MemberColumns.Count;i ++ ){ %>
30 <%= getParameter(SourceTable.PrimaryKey.MemberColumns[i]) %>
31 <% if (i > 0 ){ %> , <% } %>
32 <% } %>
33 AS
34 delete * from <%= SourceTable.Name %>
35 where
36 <% for ( int i = 0 ;i < SourceTable.PrimaryKey.MemberColumns.Count;i ++ ){ %>
37 <% if ( i > 0 ){ %> and <% } %>
38 <%= SourceTable.PrimaryKey.MemberColumns[i].Name %>= @ <%= SourceTable.PrimaryKey.MemberColumns[i].Name %>
39 <% } %>
首先这是一个把模板编译成代码的IDE,可以用C#和vb.net编写代码,点击为选择的数据库表生成删除的存储过程,很爽哦,再来个更新的,^_^
2 <% @ Property Name = " SourceTable " Type = " SchemaExplorer.TableSchema " Description = " ????-??. " %>
3 <% @ Assembly Name = " SchemaExplorer " %>
4 <% @ Import Namespace = " SchemaExplorer " %>
5 < script runat = " template " >
6 public string getParameter(ColumnSchema col)
7 {
8 String parameter = " @ " + col.Name + " " + col.NativeType;
9 switch (col.DataType)
10 {
11 case DbType.Decimal:
12 {
13 parameter += " ( " + col.Precision + " , " + col.Scale + " ) " ;
14 break ;
15 }
16 default :
17 {
18 if (col.Size > 0 )
19 {
20 parameter += " ( " + col.Size + " ) " ;
21 }
22 break ;
23 }
24 }
25 return parameter;
26 }
27 </ script >
28 create procedure dbo.Delete <%= SourceTable.Name %>
29 <% for ( int i = 0 ;i < SourceTable.PrimaryKey.MemberColumns.Count;i ++ ){ %>
30 <%= getParameter(SourceTable.PrimaryKey.MemberColumns[i]) %>
31 <% if (i > 0 ){ %> , <% } %>
32 <% } %>
33 AS
34 delete * from <%= SourceTable.Name %>
35 where
36 <% for ( int i = 0 ;i < SourceTable.PrimaryKey.MemberColumns.Count;i ++ ){ %>
37 <% if ( i > 0 ){ %> and <% } %>
38 <%= SourceTable.PrimaryKey.MemberColumns[i].Name %>= @ <%= SourceTable.PrimaryKey.MemberColumns[i].Name %>
39 <% } %>
update
1 <%@ CodeTemplate Language="C#" TargetLanguage="T-SQL" Description="????" %>
2 <%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="??????????" %>
3 <%@ Assembly Name="SchemaExplorer" %>
4 <%@ Import Namespace="SchemaExplorer" %>
5
6 CREATE PROCEDURE dbo.update<%=SourceTable.Name%>
7 <% for(int i=0;i<SourceTable.Columns.Count;i++){%>
8 <%=getParameter(SourceTable.Columns[i])%>
9 <% if(i<SourceTable.Columns.Count-1){%>,<% }%>
10 <% }%>
11 AS
12 Update <%=SourceTable.Name%> set
13 <% for(int i=0;i<SourceTable.NonPrimaryKeyColumns.Count;i++ ){%>
14 <%=SourceTable.NonPrimaryKeyColumns[i].Name%>=@<%=SourceTable.NonPrimaryKeyColumns[i].Name%>
15 <%if(SourceTable.NonPrimaryKeyColumns.Count-1>1){%>,<%}%>
16 <%}%>
17 where
18 <% for(int i=0;i<SourceTable.PrimaryKey.MemberColumns.Count;i++){%>
19 <%if(i>0){%>and<%}%>
20 <%=SourceTable.PrimaryKey.MemberColumns[i].Name%>=@<%=SourceTable.PrimaryKey.MemberColumns[i].Name%>
21 <%}%>
22 <script runat="template">
23 public string getParameter(ColumnSchema col)
24 {
25 String parameter="@"+col.Name+" "+col.NativeType;
26 switch(col.DataType)
27 {
28 case DbType.Decimal:
29 {
30 parameter+="("+col.Precision+","+col.Scale+")";
31 break;
32 }
33 default:
34 {
35 if(col.Size>0)
36 {
37 parameter+="("+col.Size+")";
38 }
39 break;
40 }
41 }
42 return parameter;
43 }
44 </script>
菜鸟火速进步中,前人铺好路,学起来也比较轻松,偶尔要加上自己的一点小创意啊,哈哈!
1 <%@ CodeTemplate Language="C#" TargetLanguage="T-SQL" Description="????" %>
2 <%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="??????????" %>
3 <%@ Assembly Name="SchemaExplorer" %>
4 <%@ Import Namespace="SchemaExplorer" %>
5
6 CREATE PROCEDURE dbo.update<%=SourceTable.Name%>
7 <% for(int i=0;i<SourceTable.Columns.Count;i++){%>
8 <%=getParameter(SourceTable.Columns[i])%>
9 <% if(i<SourceTable.Columns.Count-1){%>,<% }%>
10 <% }%>
11 AS
12 Update <%=SourceTable.Name%> set
13 <% for(int i=0;i<SourceTable.NonPrimaryKeyColumns.Count;i++ ){%>
14 <%=SourceTable.NonPrimaryKeyColumns[i].Name%>=@<%=SourceTable.NonPrimaryKeyColumns[i].Name%>
15 <%if(SourceTable.NonPrimaryKeyColumns.Count-1>1){%>,<%}%>
16 <%}%>
17 where
18 <% for(int i=0;i<SourceTable.PrimaryKey.MemberColumns.Count;i++){%>
19 <%if(i>0){%>and<%}%>
20 <%=SourceTable.PrimaryKey.MemberColumns[i].Name%>=@<%=SourceTable.PrimaryKey.MemberColumns[i].Name%>
21 <%}%>
22 <script runat="template">
23 public string getParameter(ColumnSchema col)
24 {
25 String parameter="@"+col.Name+" "+col.NativeType;
26 switch(col.DataType)
27 {
28 case DbType.Decimal:
29 {
30 parameter+="("+col.Precision+","+col.Scale+")";
31 break;
32 }
33 default:
34 {
35 if(col.Size>0)
36 {
37 parameter+="("+col.Size+")";
38 }
39 break;
40 }
41 }
42 return parameter;
43 }
44 </script>