[英]Exec Stored Procedure with output parameter in Entity Framework Core 2
I'm trying to refactor code to use dbContext.Database.ExecuteSqlCommandAsync
instead of SqlCommand
我正在尝试重构代码以使用
dbContext.Database.ExecuteSqlCommandAsync
而不是SqlCommand
List<SqlParameter> parameters = new List<SqlParameter>();
parameters.Add(new SqlParameter("@certificateTypeId", "TA"));
parameters.Add(new SqlParameter("@personId", 1m));
parameters.Add(new SqlParameter("@selfAssessment", xDocument.ToString()));
parameters.Add(new SqlParameter("@selfAssessmentVersion", 1m));
parameters.Add(new SqlParameter("@sponsorPersonId", 1m));
var outputParam = new SqlParameter("@certificationEventId", SqlDbType.Decimal, 10);
outputParam.Direction = ParameterDirection.Output;
parameters.Add(outputParam);
string sql = "[My Stored Proc] " + string.Join(" ", parameters.Select(ToEfString).ToArray());
// runtime value: [My Stored Proc] @certificateTypeId @personId @selfAssessment @selfAssessmentVersion @sponsorPersonId @certificationEventId OUT
var result = await dbContext.Database.ExecuteSqlCommandAsync(sql, parameters);
return ((SqlDecimal)outputParam.SqlValue).Value;
I'm getting this error: 我收到此错误:
SqlException: Incorrect syntax near @personId
SqlException:@personId附近的语法不正确
What's wrong? 怎么了?
您需要在参数之间添加逗号:
[My Stored Proc] @certificateTypeId, @personId, @...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.