2

I am trying to pass an entire object to a delete method of my API and the execution never gets to it.

Client (angular)

$http({
                      method: 'DELETE',
                      url: framewidth + "codebook/DeleteSection/",
                      data: $scope.codesection
                  })

Server (Web API 2)

[HttpDelete]
    public int DeleteSection(Domain.Code.CodeSection section)
    {
     //   repo.Delete(Mapper.Map<EF.Code.CodeSection>(section));

        return (section.Id);
    }

The EXACT same set up but with POST works for the method that does the Create operation. Is it nor possible to pass entire object with a DELETE verb request?

Thanks!

americanslon
  • 4,048
  • 4
  • 32
  • 57

1 Answers1

2

Why are you passing whole object when deleting? pass only id. read related question

public int DeleteSection(int id)
{
   var c = new Domain.Code.CodeSection(){ Id = id};
   db.Entry(c).State= EntityState.Deleted;
   db.SaveChanges();
   return id;
}

ref

Community
  • 1
  • 1
karaxuna
  • 26,752
  • 13
  • 82
  • 117
  • That's what I had originally . However I am using entity framework at the backend, so in order to delete an entity i first have to have an entity to delete. If I only pass the id I will have to have EF first run a SELECT just to find the entity to delete. That doesn't seem like the most efficient way. – americanslon Mar 28 '14 at 18:14
  • Ooo that's nice, I'll use that. That's what I was originally thinking but wasn't sure how to accomplish in the EF world. Thanks! – americanslon Mar 28 '14 at 18:29