Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/296.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# 如何使用linq编写带有任何量词的子查询?_C#_Linq - Fatal编程技术网

C# 如何使用linq编写带有任何量词的子查询?

C# 如何使用linq编写带有任何量词的子查询?,c#,linq,C#,Linq,我在linq中使用any时遇到问题,我不知道如何正确使用它。 我必须用linq写下这句话: SELECT ename, job, deptno FROM emp WHERE sal > ANY ( SELECT DISTINCT sal FROM emp WHERE deptno = 30 ); 我只写这句话: var min = (from emp in Emps where emp.Deptno == 30 sele

我在linq中使用any时遇到问题,我不知道如何正确使用它。 我必须用linq写下这句话:

SELECT ename, job, deptno
FROM emp
WHERE sal > ANY
(
    SELECT DISTINCT sal
    FROM emp
    WHERE deptno = 30
);
我只写这句话:

var min = (from emp in Emps
           where emp.Deptno == 30
           select emp.Sal
          ).Distinct();

var result = (from emp in Emps
              where min.Any() > emp.Sal
              select new
              {
                  emp.Ename
              });
Linq没有Sql Server那样的运算符

var salariesInTargetDepartment = Emps
    .Where(x => x.Deptno == 30)
    .Select(x => x.Sal)
    .Distinct()
    .ToList(); // the ToList is not required, but seeing you're going to be executing
               // against this query many times, it will be better to cache the results.

var matchingEmployees = Emps
    .Where(emp => salariesInTargetDepartment
        .Any(target => emp.Sal > target)
    );

第二条语句中的where子句表示,如果此记录的Sal属性大于salariesInTargetDepartment集合中的至少一个条目,则仅包括此记录。

此查询摘要正确吗?选择薪资高于30部门中至少一名其他员工的所有员工为什么要返回一个最小值范围?看起来SQL在30部门获得了一个最低工资。因此,min查询应该将Distinct替换为.Minx=>x,或者将where min.Any替换为Minx=>x@gunr2171是的,我必须使用任何操作符。