错误信息:[仅限基本类型或枚举类型在这方面的支持与QUOT;。 [英] Error Message: "Only primitive types or enumeration types are supported in this context."
问题描述
我在为一个asp.net页面的报告,我想这个LINQ语句的结果分配给现有的数据集,但我收到了只有原始类型或枚举类型,在这方面的支持。错误信息。这里是我的code:
VAR contextTable =新dbpersonnelEntities();
VAR contextHistory =新WriterInResidenceEntities(); VAR RSLT =(从contextTable.TableofOrganizationRptsÇ
哪里!(从o在contextHistory.emp_history
选择o.employeeID)。载有((INT)c.employeeid_fk)
选择C).ToList(); ReportDataSource R =新ReportDataSource(tableOfOrgDS,RSLT);
您不能混用从单一的LINQ查询不同的上下文中的实体类型。要么把它们放到单个的上下文,或者试图执行这样的:
VAR employeeIds =(邻在contextHistory.emp_history选择o.employeeID).ToList();
然后通过这个列表进入第二查询:
VAR RSLT =(从C在contextTable.TableofOrganizationRpts
哪里!employeeIds.Contains((INT)c.employeeid_fk)
选择C).ToList();
本应产生结果的SQL查询在
状态。请注意,这可能工作缓慢。
I'm working a report for an asp.net page and I'm trying to assign the results of this linq statement to an existing dataset but I'm receiving the "Only primitive types or enumeration types are supported in this context." Error message. Here's my code:
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);
You can't mix entity types from different contexts in single LINQ query. Either put them into single context, or try to execute this:
var employeeIds = (from o in contextHistory.emp_history select o.employeeID).ToList();
and then pass this list into the second query:
var rslt = (from c in contextTable.TableofOrganizationRpts
where !employeeIds.Contains((int)c.employeeid_fk)
select c).ToList();
This should generate IN
condition in resulting SQL query. Note, that this might work slow.
这篇关于错误信息:[仅限基本类型或枚举类型在这方面的支持与QUOT;。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!