首页 > 解决方案 > core 2.1 webapi 并发删除

问题描述

目前我有一个可以删除的 webapi,但我需要确保只有在提供正确/当前版本的情况下才能删除它们。

我的模型是这样的:

public class Item {
    public int Id {get;set;}

    .. other properties ...

    [Timestamp]
    public byte[] Version {get;set;}
} 

我目前有以下端点声明:

[HttpDelete("{id}")]
public IActionResult Delete(int id)
{
   ...
}

有人可以让我知道发送 byte[] 版本以便在删除之前进行检查的正确方法是什么?

为了实现这一点,我需要在删除端点声明(上图)中进行哪些更改?

提前致谢。

标签: .netasp.net-coreasp.net-core-webapi

解决方案


您可以在请求的正文中传递您的时间戳。

public class DeleteItemRequest {
    public byte[] Version {get;set;}
} 

[HttpDelete("{id}")]
public IActionResult Delete(int id, [FromBody]DeleteItemRequest request)
{
   ...
}

推荐阅读