Reputation: 1019
Let's see if I can make the step-by-step clear:
namespace InventoryManager.Controllers
{
public class InventoryController : ApiController
{
private readonly IInventoryRepository repository;
//...
public HttpResponseMessage DeleteItem(int id)
{
// Executes fine
repository.Remove(id);
return new HttpResponseMessage(HttpStatusCode.NoContent);
}
}
}
Which is executing the Remove
method defined in InventoryRepository
:
namespace InventoryManager.Models
{
public class InventoryRepository : IInventoryRepository
{
private InventoryContext context;
//...
public void Remove(int id)
{
InventoryItem item = context.Items.Find(id);
// Executes fine
context.Items.Remove(item);
}
}
}
But, I check my DB and no items are removed. Why is this? There may be some information missing, so let me know what else you require.
I'm having issues debugging this because I'm out of my element. If you have methods of debugging this, or certain things/keywords I can look up to help solve my issue, I would be thankful.
Upvotes: 1
Views: 78
Reputation: 603
try this
public void Remove(int id)
{
InventoryItem item = context.Items.Find(id);
context.Items.Remove(item);
context.SaveChanges();
}
Upvotes: 1
Reputation: 35409
Make sure you're committing the changes you make to Items
against your DataContext
:
context.SubmitChanges();
context.SaveChanges();
Upvotes: 5