【发布时间】:2021-11-16 12:59:21
【问题描述】:
我想在 get api 中使用 sql 查询:
[Route("empLevel/{id}")]
public IActionResult GetEmpHierarchy(int id)
{
List<Employee> emp = entity.Employees.ToList();
List<Employee> mngr = entity.Employees.ToList();
var query = (from e in emp
join m in mngr on e.MngId equals m.Id into tab1
from mngrN in tab1.DefaultIfEmpty()
select new Employee { Id = e, MngId = m}).ToList();
return Ok(query);
}
但我在ID = e 行收到一个错误,它说e 不能转换为int。
在我的模型课中,我有:
public partial class Employee
{
public int Id { get; set; }
public string Name { get; set; }
public double Grade { get; set; }
public int? MngId { get; set; }
public virtual SalarySplit GradeNavigation { get; set; }
}
请给出解决方案。
【问题讨论】:
标签: c# entity-framework asp.net-core asp.net-web-api get