model-view-controller - 如何使用 web api 从两个表中获取数据
问题描述
我想使用 web api 从两个表中获取数据,但我收到一个错误。
这是我的代码:
public List<tblEmpTask> GettblEmpTasks()
{
var q = (from n in db.tblEmpTasks
join c in db.tblEmployees on n.intEmpCode equals c.intEmpCode
select new
{
n.strTaskName,
n.dtStart,
c.strEmployeeName,
}).ToList();
return q;
}
这是我收到的错误:
The type of one of the expressions in the join clause is incorrect. Type inference failed in the call to 'Join'.
请注意,我使用的是 web api。期待解决这个问题。
解决方案
选择匿名函数时,该函数应返回List<object>
,或者改为
使用类型返回值,例如 -
class myType{
string TaskName, //assuming type as string
string dtStart, //assuming type as string
string EmployeeName //assuming type as string
}
并在 LinQ 查询中类似于 -
select new myType{ TaskName=n.strTaskName, dtStart=n.dtStart, EmployeeName=c.strEmployeeName}
并返回为List<myType>
推荐阅读
- vba - 函数 SUM vba
- java - 将摇动应用程序作为项目的短信
- java - 如何在 spring-boot-2 中添加 WebRequestTraceFilter?
- python - Python 请求 - Put 忽略文件上传
- c++ - 如何将动作委托给函数返回?
- powershell - Powershell 5.0 和 5.1 中的 Get-ChildItem
- python-3.x - pyautogui 上的 typewrite(),press() 在远程桌面上不起作用
- snmp - 我可以用来开发 Netconf 客户端和服务器的 C/C++(开源)SDK 是什么
- angular - 如何将我的angular1.6项目的现有结构迁移到angular 5/6
- javascript - Angular 6 i18n 动态翻译