不知道能不能用,我看provider只有2種,一種為sqlSchemaprovider,還有一個為adoxschemaprovider,模板寫好後,編譯就提示錯誤,
在對應所需名稱或序數的集合中,未找到項目。
An error of type "COMException"
occured while attempting to execute this template. To enable
Just-In-Time debugging on this template set the "Debug" attribute to
"True" in the "CodeTemplate" directive and add a "Debugger.Break()"
statement in the template.
下面為我的模板
<%@ CodeTemplate Language="C#" TargetLanguage="T-SQL"
Description="Generates a update stored procedure." %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema"
Category="Context"
Description="Table that the stored procedures should be based on." %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<script runat="template">
public string GetSqlParameterStatement(ColumnSchema column)
{
string param = "@" + column.Name + " " + column.NativeType;
switch (column.DataType)
{
case DbType.Decimal:
{
param += "(" + column.Precision + ", " + column.Scale + ")";
break;
}
default:
{
if (column.Size > 0)
{
param += "(" + column.Size + ")";
}
break;
}
}
return param;
}
</script>
-----------------------------------------------------------------
-- Date Created: <%= DateTime.Now.ToLongDateString() %>
-- Created By: Generated by CodeSmith
-----------------------------------------------------------------
CREATE PROCEDURE dbo.Update<%= SourceTable.Name %>
<% for (int i = 0; i < SourceTable.Columns.Count; i++) { %>
<%=
GetSqlParameterStatement(SourceTable.Columns[i]) %><% if (i <
SourceTable.Columns.Count - 1) { %>,<% } %>
<% } %>
AS
UPDATE [<%= SourceTable.Name %>] SET
<% for (int i = 0; i < SourceTable.NonPrimaryKeyColumns.Count; i++) { %>
[<%=
SourceTable.NonPrimaryKeyColumns[i].Name %>] = @<%=
SourceTable.NonPrimaryKeyColumns[i].Name %><% if (i <
SourceTable.NonPrimaryKeyColumns.Count - 1) { %>,<% } %>
<% } %>
WHERE
<% for (int i = 0; i < SourceTable.PrimaryKey.MemberColumns.Count; i++) { %>
<% if (i > 0) { %>AND <% } %>
[<%=
SourceTable.PrimaryKey.MemberColumns[i].Name %>] = @<%=
SourceTable.PrimaryKey.MemberColumns[i].Name %>
<% } %>
sql server已經通過了。oracle則提示上面的錯誤。