我想使用SqlProcedure方法,但我看到第一个参数作为anon对象...我认为它是传递商店的参数但我没有看到传递SP名称的位置...我做错了什么?
string sp = StoredProcedureHelper.Instance.GetStoreProcedureName("mySP");
var dataTable = dbConn.SqlProcedure<myPOCO>(new
{
ID_ISTITUTO = header.Istituto,
ID_CANALE = header.MC_CHANNEL,
OPERATORE = header.MC_USERID,
NDG = header.MC_NDG,
DOSSIER = header.Dossier
});
我在哪里指定命令文本?
我受v4谢谢
答案 0 :(得分:2)
您可以使用 SqlList 来调用自定义SQL:
List<Poco> results = db.SqlList<Poco>("EXEC GetAnalyticsForWeek @weekNo",
new { weekNo = 1 });
通过https://github.com/ServiceStack/ServiceStack.OrmLite/#new-apis-to-execute-custom-sql
以下是更多示例的单元测试
答案 1 :(得分:2)
查看SqlProcedure
示例here
您需要创建一个类来表示参数,并将其别名为存储过程名称。
[Alias("SUB_TOT_BUDGET")]
public class ProcedureSubTotalBudgetParameters
{
[Alias("HEAD_DEPT")]
public string HeadDepartment
{
get;
set;
}
}
public class ProcedureSubTotalBudgetResult
{
[Alias("TOT_BUDGET")]
public decimal Total
{
get;
set;
}
[Alias("AVG_BUDGET")]
public decimal Average
{
get;
set;
}
[Alias("MAX_BUDGET")]
public decimal Max
{
get;
set;
}
[Alias("MIN_BUDGET")]
public decimal Min
{
get;
set;
}
}
ProcedureSubTotalBudgetParameters p = new ProcedureSubTotalBudgetParameters() {
HeadDepartment = "000"
};
var results = db.SqlProcedure<ProcedureSubTotalBudgetResult>(p, "");