【发布时间】:2020-02-22 16:52:45
【问题描述】:
我正在关注并实施以下项目: https://docs.microsoft.com/es-mx/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.0&tabs=visual-studio
但是在调用[HttpGet("{id}")]的部分,它只适用于id字段,但我想检索存储在DBmemory中的JSON,用其他字段代替id;在这种情况下,我想按字段TAG 管理数据。
我怎样才能做到这一点?
我尝试将所有id 部分更改为TAG,这是我正在寻找的字段,但是当我这样做时,post 方法会中断。
// GET: api/Maquinas/5
[HttpGet("{id}")]
public async Task<ActionResult<Maquina>> GetMaquina(string id)
{
// HERE. i need to find data with the field of "TAG" not "id"
var maquina = await _context.Maquinas.FindAsync(id);
if (maquina == null)
{
return NotFound();
}
return maquina;
}
【问题讨论】:
-
当它“分手”时会发生什么?因为用 TAG 替换 id 将是我的处理方式。
标签: c# asp.net-web-api http-get