Error Message: “Only primitive types or enumeration types are supported in this context.”

限于喜欢 提交于 2020-01-21 16:36:27

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/16836516/error-message-only-primitive-types-or-enumeration-types-are-supported-in-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!