可以了,能不能帮忙看下这段代码有什么问题
#region Insert
public int Insert(<%=GetPascalName(SourceTable.Name)%>Entity <%=GetCamelCaseName(SourceTable.Name)%>Entity)
{
SqlCommand cmd = new SqlCommand();
            string sql = @"insert into <%=SourceTable.Name%>(<%for(int i=0;i<SourceTable.Columns.Count;i++){ if((bool)(SourceTable.Columns[i].ExtendedProperties["CS_IdentityIncrement"].Value)==false){%><%="["+SourceTable.Columns[i].Name + (i==SourceTable.Columns.Count-1?"]":"], ")%><%}%>) values(<%for(int k=0;k<SourceTable.Columns.Count;k++){%>@<%=SourceTable.Columns[k].Name + (k==SourceTable.Columns.Count-1?"":", ")%><%}}%>)";
            cmd.CommandText = sql;
            SqlParameterCollection paramCollection = cmd.Parameters;
<%foreach(ColumnSchema col in SourceTable.Columns){ if((bool)(col.ExtendedProperties["CS_IdentityIncrement"].Value)==false){%>
paramCollection.Add(new SqlParameter("@<%=col.Name%>", SqlDbType.<%=GetSqlDbType(col)%>));
<%}}%>
<%foreach(ColumnSchema col in SourceTable.Columns){ if((bool)(col.ExtendedProperties["CS_IdentityIncrement"].Value)==false){%>
if (<%=GetCamelCaseName(SourceTable.Name)%>Entity.<%=GetPascalName(col.Name)%> == null)
            {
                paramCollection["@<%=col.Name%>"].Value = DBNull.Value;
            }
            else
            {
                paramCollection["@<%=col.Name%>"].Value = <%=GetCamelCaseName(SourceTable.Name)%>Entity.<%=GetPascalName(col.Name)%>;
            }
<%}}%>
return new DataHelper().ExecuteNonQuery(cmd);
}
#endregion
估计是if((bool)(SourceTable.Columns[i].ExtendedProperties["CS_IdentityIncrement"].Value)==false)这段的问题,把这些去掉就可以生成
生成的时候报错如下:
System.InvalidCastException: 指定的转换无效。
   在 _CodeSmith.TestDataAccessObject_cst.__RenderMethod1(TextWriter writer, Control control)
   在 CodeSmith.Engine.DelegateControl.Render(TextWriter writer)
   在 CodeSmith.Engine.Control.RenderChildren(TextWriter writer)
   在 CodeSmith.Engine.CodeTemplate.Render(TextWriter writer)
   在 CodeSmith.Engine.CodeTemplate.RenderToString()
   在 CodeSmith.Gui.CodeTemplateGenerator.f(Object A_0, EventArgs A_1)
是不是用这个要引用什么?