我需要使用EF 6.1将十进制\ money传递给C#中的存储过程并获得结果。 但是我得到了错误:
System.Data.SqlClient.SqlException:将数据类型 nvarchar 转换为资金时出错。
SP看起来像这样:
ALTER PROCEDURE [dbo].[spUpdateContractCash]
@UserId uniqueidentifier,
-- other int params
@Year_01 money -- cant convert this param
AS
BEGIN
-- some logic
SELECT 1 as StatusCode, 'Success' as StatusMessage -- result
END
更新方法的存储库代码:
public new string Update(ContractCashSp entity)
{
var userId = new SqlParameter("UserId", entity.UserId);
var year1 = new SqlParameter("Year_01", SqlDbType.Money) { Value = entity.CashContainer.Year1, Precision = 10, Scale = 2};
string procedureQuery = string.Format("exec spUpdateContractCash @UserId, @Year_01");
IList<object> paramsList = new List<object>();
paramsList.Add(userId);
paramsList.Add(year1);
StoredProcedureResult result = ExecuteSqlQuery(procedureQuery, paramsList.ToArray()).First();
return result.StatusMessage;
}
protected DbRawSqlQuery<StoredProcedureResult> ExecuteSqlQuery(string procedureQuery, object[] parameters)
{
return dbContext.Database.SqlQuery<StoredProcedureResult>(procedureQuery, parameters);
}
下一步显示SQL请求的跟踪:
exec sp_executesql N'spUpdateContractCash @UserId, @Year_01',
N'@UserId uniqueidentifier,
@Year_01 money',
@UserId='15352797-B907-49EA-9120-34BBB8DFA1DD',
@Year_01=$334785.0000
如何将十进制值传递给存储过程并减少此问题?