【问题标题】:How to implement get by id in ASP.NET Web API?如何在 ASP.NET Web API 中实现通过 id 获取?
【发布时间】:2023-01-11 12:58:00
【问题描述】:

当我尝试实现 get by id SPI 服务时,我得到了所有记录,而不是 ASP.NET Core Web API 中的一个特定记录。

        [HttpGet("EmployeeId")]
        public ActionResult<Employeedatum> Getbyid(int EmployeeId)
        {
           if(EmployeeId <= 0)
            {
                return NotFound("not found");
            }
            Employeedatum employeedata = DbContext.Employeedatum.FirstOrDefault(s => s.empid == EmployeeId);
            if(employeedata == null)
            {
                return NotFound("notfound");
            }
            return Ok(employeedata);

This is my code.

【问题讨论】:

  • 节目是Employeedatum
  • 你能解释清楚吗?

标签: c# asp.net sql-server asp.net-mvc asp.net-web-api


【解决方案1】:

试试这个作为 Lync 查询

Employeedatum employeedata = DbContext.Employeedatum.where(s => s.empid == EmployeeId).FirstOrDefault();

【讨论】:

  • 你是说 LINQ 查询吗?
猜你喜欢
  • 2015-08-17
  • 1970-01-01
  • 2021-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-02
相关资源
最近更新 更多