-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 it in the 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 running by API(Postman) do not delete. No error, but do not delete.
The database is sql server. When Proc is run by Sql Server, it works fine.
Debugging, you’re falling for this API action?
– Leandro Angelo
Yes, I fall into the controller and then I give an F11 and I go to the method and the parameter is coming right
– pnet
Changes the code to
banco.Database.ExecuteSqlCommand("exec sp_del_cidade", new SqlParameter("@id", id));
as I’m not sure I’ll leave comment, if I resolve I reply– Barbetta
I have it:
System.Data.SqlClient.SqlException: 'O procedimento ou a função 'sp_del_cidade' espera o parâmetro '@id', que não foi fornecido.'
for this purpose:banco.Database.ExecuteSqlCommand("exec sp_del_cidade", new SqlParameter("@id", id));
– pnet
Changes the code to
banco.Database.ExecuteSqlCommand("exec sp_del_cidade @id", new SqlParameter("@id", id));
try again, actually do two tests, the one before and this:banco.Database.SqlQuery<Cidade>("exec sp_del_cidade @id", new SqlParameter("@id", id));
, confirm if both or only 1 works, please.– Barbetta
@Barbetta, put on the last one I mark. It worked.
– pnet
with Sqlquery worked?
– Barbetta
@Barbetta, I didn’t even test anymore. I’m late in what I screwed up.
– pnet
@Barbetta, for the Post is giving the same parameter error. I did similar to delete, but pointing to the SP insertion.
– pnet
Let’s go continue this discussion in chat.
– Barbetta