我已经使用 MVC4 和 C# 创建了一个 API。我的一些命令有问题。我不断收到此错误:“'API.Controllers.EmployeesController.GetDepartment(int)' 的最佳重载匹配有一些无效参数。” 下面是我的代码。我在调用类似函数的三个不同行上收到错误。发送给函数的值有可能为空。
public List<Models.Position> GetPositions(int EmployeeID)
{
var positions = from position in _context.tbl_positions
where position.people_ID == EmployeeID
select new Models.Position
{
PositionID = position.id
,Department = position.dept_ID == null ? string.Empty : GetDepartment(position.dept_ID)
,JobTitle = position.title
,Building = position.location_ID == null ? string.Empty : GetBuilding(position.location_ID)
,Room = position.room
,Phone = position.public3 == null ? string.Empty : "000-111-" + position.public3
,Fax = position.fax3 == null ? string.Empty : "000-111-" + position.fax3
,College = position.college_ID == null ? string.Empty ? GetCollege(position.college_ID)
};
return positions.ToList();
}
public string GetDepartment(int DeptId)
{
var department = (from departments in _context.tbl_departments
where departments.ID == DeptId
select departments.dept).SingleOrDefault();
return department;
}
public string GetBuilding(int BID)
{
var building = (from buildings in _context.tbl_locations
where buildings.id == BID
select buildings.Name).FirstOrDefault();
return building;
}
public string GetCollege(int CID)
{
var college = (from colleges in _context.tbl_colleges
where colleges.id == CID
select colleges.college).SingleOrDefault();
return college;
}