我有一个类。以及其中的一些方法..,其中我传递了一些存储过程..
e.g。
Class Invoice
{
public string storedProcedure;
public void insert(object[] para)
{
Database obj = DatabaseFactory.CreateDatabase();
obj.ExecuteNonQuery(storedProcedure, para);
}
}
我想将存储过程存储为键值对..以便我以后可以使用它们。
那么,如何以及在哪里存储这些值..,以便我以后可以在编码中访问它们。?
答案 0 :(得分:1)
创建另一个静态类StoredProcedureManager
为
public static class StoredProcedureManager
{
public static string GetEmployeeDetails = "sp_GetEmployeeDetails";
public static string UpdateEmployeeName = "sp_updateEmployeeName";
// you can statically type these names or load them from file or database
. . .
}
注意:访问说明符取决于您希望提供给StoredProcedureManager类的范围
要访问SP名称:
obj.ExecuteNonQuery(StoredProcedureManager.GetEmployeeDetails);
如果存储在词典中必须
public static class StoredProcedureManager
{
public static Dictionary<string, string> Procedures = new Dictionary<string, string>();
static StoredProcedureManager()
{
procedures.Add("GetEmployeeDetails", "sp_GetEmployeeDetails");
procedures.Add("UpdateEmployeeName", "sp_updateEmployeeName");
// you can statically type these names or load them from file or database
. . .
}
}
要访问SP名称:
obj.ExecuteNonQuery(StoredProcedureManager.Procedures["GetEmployeeDetails"]);