gpt4 book ai didi

c# - 错误消息 : "Only primitive types or enumeration types are supported in this context."

转载 作者:太空宇宙 更新时间:2023-11-03 16:12:54 25 4
gpt4 key购买 nike

我正在为一个 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);

最佳答案

您不能在单个 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 条件。请注意,这可能会很慢。

关于c# - 错误消息 : "Only primitive types or enumeration types are supported in this context.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16836516/

25 4 0