【问题标题】:SubSonic 3.0 stored procedure generationSubSonic 3.0 存储过程生成
【发布时间】:2009-08-04 17:41:33
【问题描述】:
当使用 SubSonic 3.0.0.3 和 StoredProcedures.tt 模板时,生成的代码将无法编译并抛出错误:
...“DB”不包含“Provider”的定义...
这是在存储过程的调用方法中。
StoredProcedure sp = new StoredProcedure("Company_Get", this.Provider);
是我遗漏了什么还是 3.0 模板中用于生成存储过程包装器的错误?
【问题讨论】:
标签:
stored-procedures
subsonic3
【解决方案1】:
我猜想我们这些想要使用 SubSonic v3 的人处于最前沿。我还需要使用 context.tt 生成代码。这纠正了我的问题。这真的很酷,但是屏幕投射和文档跟不上产品发展的速度。
【解决方案2】:
public ProcedureParameters Parameters
{
get
{
return sp;
}
set
{
sp = value;
}
}
# region "Constructors"
public ExecuteProcedures(int ParameterLength, string ConnectionString):base(true,ConnectionString)
{
sp = new ProcedureParameters(ParameterLength);
strConnection = ConnectionString;
}
#endregion
# region "Execute Procedures"
public bool InvokeProcedure(string ProcedureName, SqlTransaction SqlTrn, SqlConnection con)
{
SqlCommand Sqlcmd = new SqlCommand();
try
{
Sqlcmd.CommandType = CommandType.StoredProcedure;
Sqlcmd.Connection = con;
Sqlcmd.Transaction = SqlTrn;
Sqlcmd.CommandText = ProcedureName;
Sqlcmd.Parameters.AddRange(sp.ParameterCollection);
Sqlcmd.ExecuteNonQuery();
return true;
}
catch (Exception e)
{
con.Close();
SqlTrn.Rollback();
throw new Exception("Error Occured :-" + e.Message, e);
}
finally
{
Sqlcmd.Dispose();
}
}
public bool InvokeProcedure(string ProcedureName)
{
SqlCommand Sqlcmd = new SqlCommand();
SqlConnection con = new SqlConnection(strConnection);
try
{
Sqlcmd.CommandType = CommandType.StoredProcedure;
Sqlcmd.Connection = con;
Sqlcmd.CommandText = ProcedureName;
Sqlcmd.Parameters.AddRange(sp.ParameterCollection);
con.Open();
Sqlcmd.ExecuteNonQuery();
return true;
}
catch (Exception e)
{
throw new Exception("Error Occured :-" + e.Message, e);
}
finally
{
con.Close();
Sqlcmd.Dispose();
con.Dispose();
}
}
【解决方案3】:
我相信你在几年前就已经得到了答案,但是你需要运行所有的 ActiveRecord 模板,包括 Struct 和 Context。