2

我正在为 asp.net 页面编写报告,并且正在尝试将此 linq 语句的结果分配给现有数据集,但我收到“在此上下文中仅支持原始类型或枚举类型”。错误信息。这是我的代码:

   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);
4

1 回答 1

0

您不能在单个 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();

这应该IN在生成的 SQL 查询中生成条件。请注意,这可能会运行缓慢。

于 2013-05-30T14:09:05.733 回答