【问题标题】:core 2.1 webapi delete with concurrencycore 2.1 webapi 并发删除
【发布时间】:2018-07-11 00:59:39
【问题描述】:

目前我有一个可以删除的 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[] 版本以便在删除之前进行检查的正确方法是什么吗?

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

提前致谢。

【问题讨论】:

    标签: .net asp.net-core asp.net-core-webapi


    【解决方案1】:

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

    public class DeleteItemRequest {
        public byte[] Version {get;set;}
    } 
    
    [HttpDelete("{id}")]
    public IActionResult Delete(int id, [FromBody]DeleteItemRequest request)
    {
       ...
    }
    

    【讨论】:

      猜你喜欢
      • 2019-08-30
      • 2019-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-25
      • 1970-01-01
      • 2015-08-15
      • 2019-12-27
      相关资源
      最近更新 更多