linq 错误消息:“在此上下文中只支持基元类型或枚举类型.”

zkure5ic  于 2022-12-06  发布在  其他
关注(0)|答案(1)|浏览(153)

我正在为一个www.example.com页面编写一个报告asp.net,我试图将这个linq语句的结果赋给一个现有的数据集,但是我收到了“Only primitive types or enumeration types are supported in this context.”错误消息。下面是我的代码:

var contextTable = new dbpersonnelEntities();                
   var contextHistory = new WriterInResidenceEntities();

   var rslt = (from c in contextTable.TableofOrganizationRpts
            where !(from o in contextHistory.emp_history
            select o.employeeID).Contains((int)c.employeeid_fk)
                       select c).ToList();

   ReportDataSource r = new ReportDataSource("tableOfOrgDS", rslt);
5n0oy7gb

5n0oy7gb1#

不能在单个LINQ查询中混合不同上下文中的实体类型。请将它们放入单个上下文中,或尝试执行以下操作:

var employeeIds = (from o in contextHistory.emp_history select o.employeeID).ToList();

然后将该列表传递到第二个查询中:

var rslt = (from c in contextTable.TableofOrganizationRpts
            where !employeeIds.Contains((int)c.employeeid_fk)
            select c).ToList();

这将在结果SQL查询中生成IN条件请注意,这可能会运行缓慢

相关问题