Jos*_*osh 1 c# asp.net-mvc asp.net-web-api
让我们看看我是否可以逐步明确:
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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是执行以下Remove定义的方法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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是,我检查我的数据库,没有删除任何项目.为什么是这样?可能缺少某些信息,请告诉我您还需要什么.
我在调试这个问题是因为我不在我的元素中.如果您有调试方法,或者我可以查找某些事情/关键字以帮助解决我的问题,我将非常感激.
请确保您提交您对改变Items对你DataContext:
context.SubmitChanges();
Run Code Online (Sandbox Code Playgroud)
context.SaveChanges();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
57 次 |
| 最近记录: |