Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 林克';其中';第1929条_C#_Linq - Fatal编程技术网

C# 林克';其中';第1929条

C# 林克';其中';第1929条,c#,linq,C#,Linq,仍然在学习Linq的细微差别。 研究过了,但没能找到一个解决方案,我认为这是一个简单的解决办法 编辑:根据要求,这里是完整的代码块: //Jboyd pull back all relative orgs var parent = from s in Students where s.Id==5027 select new { ID_PK = s.CaseOwnerIdAspnet_Users.User_ID_FKDYN_User_Profile.Organization_ID_FKD

仍然在学习Linq的细微差别。 研究过了,但没能找到一个解决方案,我认为这是一个简单的解决办法

编辑:根据要求,这里是完整的代码块:

//Jboyd pull back all relative orgs
var parent =
from s in Students
where s.Id==5027
select new { 
    ID_PK = s.CaseOwnerIdAspnet_Users.User_ID_FKDYN_User_Profile.Organization_ID_FKDYN_Organization.Parent_ID_FK == null ?
    (int) s.CaseOwnerIdAspnet_Users.User_ID_FKDYN_User_Profile.Organization_ID_FKDYN_Organization.ID_PK
    :
    (int) s.CaseOwnerIdAspnet_Users.User_ID_FKDYN_User_Profile.Organization_ID_FKDYN_Organization.Parent_ID_FK
    };

var orgs = 
from o in DYN_Organizations
join p in parent on o.Parent_ID_FK equals p.ID_PK
select new {ID_PK = o.ID_PK};

var unionOrgs = parent.Union(orgs) ;
//unionOrgs是组织的列表 //下面的查询:我需要查询一个更大的表,其中ORG在上面的列表中

var userProfilesQuery = from up in DYN_User_Profiles
where unionOrgs.Contains(up.Organization_ID_FK) //this is where the error occurs 
select up;
错误: CS1929“IQueryable”不包含“Contains”的定义,而最佳扩展方法重载“ParallelEnumerable.Contains(ParallelQuery,int)”需要“ParallelQuery”类型的接收器


实际上,目标是unionOrgs返回一个orgs列表。然后我想查询一个更大的表,查找该列表中的任何组织

组织
不是单个实例,而是一个集合,这就是为什么它没有
ID\u PK
属性的原因。而是使用
包含

var orgs = from o in DYN_Organizations
           join p in parent on o.Parent_ID_FK equals p.ID_PK
           select o.ID_PK;

var query = from up in userProfilesQuery
            where orgs.Contains(up.Organization_ID_FK) 
            select up;
另请参见,当您使用单个字段投影匿名对象时,您也可以只投影属性并接收
IQueryable
,而不是
IQueryable

特别是对于第二个查询,我发现方法语法更干净:

var query = userProfilesQuery.Where(up => orgs.Contains(up.Organization_ID_FK));

这是因为
orgs
是具有
ID\u PK
s属性的对象集合。你想做什么?
IQueryable
inherits
IEnumerable
正如@gilad所指出的,你的组织是一个集合。对你的类名和属性名做点什么。这很难理解(而且你必须一直这么做!)。感谢您的快速反馈。通过以上两种解决方案,我得到了一个新错误:CS1929“IQueryable”不包含“Contains”的定义,而最佳扩展方法重载“ParallelEnumerable.Contains(ParallelQuery,int)”需要一个类型为“ParallelQuery”的接收者@JoshuaBoyd为我们提供了完整的代码,您粘贴的内容(向我们展示DYN_Organizations和userProfilesQuery是什么类型,以及它们是如何声明的,理想情况下粘贴整个函数)无法扣除更多。对于持续更新,我深表歉意。我试图通过提取我认为是相对的内容来简化代码,但有多个请求发布完整的代码块。非常感谢你的帮助-