I have this code where I’m trying to get the results of a stored procedure. I’m getting the error “the required column Quantidade was not present in the results of a fromsql operation”. This happens even though on sql profiler the variables are getting the correct values when I call the method.
I have “ToList” after the call but I tried lots of other things. StoredProcedResult here is a keyless class in the shape of the results I’m expecting. And I also tried assigning the values from the SqlParameter variables to something else, but it was null. I’m new to coding so be patient here lol.
Already tried searching for answers online and applied many different things suggested but it didn’t work. Thanks already!
public async Task<StoredProcedureResult> ExecSprocAsync()
{
// var sprocresult = await _apoloDbContext.StoredProcedureResults.FromSqlInterpolated($"EXECUTE CRK_LIMITES @EmpCod = {empcod}, @EntCod = {entcod}, @Pedido = {pedido}")
// .ToListAsync()
// return sprocresult;
string empCod = "1";
string entCod = "1";
string pedido = "1";
var quantidadeParam = new SqlParameter("@Quantidade", SqlDbType.Int) { Direction = ParameterDirection.Output };
var recNaoPagoParam = new SqlParameter("@RecNaoPago", SqlDbType.Decimal) { Direction = ParameterDirection.Output };
var limiteCredParam = new SqlParameter("@LimiteCred", SqlDbType.Decimal) { Direction = ParameterDirection.Output };
var pedidosReceberParam = new SqlParameter("@PedidosReceber", SqlDbType.Decimal) { Direction = ParameterDirection.Output };
var creditoDisponivelParam = new SqlParameter("@CreditoDisponivel", SqlDbType.Decimal) { Direction = ParameterDirection.Output };
var valorSaldoPedidosParam = new SqlParameter("@ValorSaldoPedidos", SqlDbType.Decimal) { Direction = ParameterDirection.Output };
var result = _apoloDbContext.StoredProcedureResults
.FromSqlInterpolated($"EXECUTE CRK_LIMITES {empCod}, {entCod}, {pedido}, {quantidadeParam} out, {recNaoPagoParam} out, {limiteCredParam} out, {pedidosReceberParam} out, {creditoDisponivelParam} out, {valorSaldoPedidosParam} out")
.ToList();
1