Api to delete is not working, does not delete. A Stored Procedure on the bank is working

-2

This is the API

public class DeleteCidade
    {
        BancoContext banco = new BancoContext(); 
        public void deleteCidade(int id)
        {
            banco.Database.SqlQuery<Cidade>("exec sp_del_cidade", new SqlParameter("@id", id));
        }          
    }

My cobtroller

[RoutePrefix("api/[controller]")]
    public class DeleteCidadeController : ApiController
    {
        DeleteCidade deleta = new DeleteCidade();

        [AcceptVerbs("Delete")]
        public void deleteCidade(int id)
        {
            deleta.deleteCidade(id);
        }
    }

As I call on Postman

http://localhost:55080/api/DeleteCidade/27

My SP

ALTER PROCEDURE [dbo].[sp_del_cidade] @id int
AS
BEGIN
  SET NOCOUNT ON
    delete from cidade
    where id = @id
END

When run by the API (Postman) does not delete. It gives no error, but does not delete.

The database is the sql server. The proc when run by Sql Server, works fine.

    
asked by anonymous 08.08.2018 / 21:43

1 answer

1

It has two problems, i) the command SqlQuery is to return entities, in case you are trying to perform an action. ii) the variable is not being entered after the 'procedure'.

change to:

banco.Database.ExecuteSqlCommand("exec sp_del_cidade @id", new SqlParameter("@id", id));
    
08.08.2018 / 22:24