Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.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# 带有子where子句的LINQ查询_C#_Linq - Fatal编程技术网

C# 带有子where子句的LINQ查询

C# 带有子where子句的LINQ查询,c#,linq,C#,Linq,我有一个SQL查询: SELECT [Paypoint] ,[Department] ,[EmployeeCode] ,[Gender] ,[EmployeeTitle] ,[Initials] ,[Surname] ,[ItemsIssuedDate] ,[ItemsIssuedStockNumber] FROM [MyTable] AS a WHERE ( [ItemsIs

我有一个SQL查询:

 SELECT [Paypoint]
      ,[Department]
      ,[EmployeeCode]
      ,[Gender]
      ,[EmployeeTitle]
      ,[Initials]
      ,[Surname]
      ,[ItemsIssuedDate]
      ,[ItemsIssuedStockNumber]
  FROM [MyTable] AS a
  WHERE
 (
      [ItemsIssuedDate] =   (   SELECT     max([ItemsIssuedDate])
                                FROM        [MyTable] AS b
                                WHERE       a.[Paypoint] = b.[Paypoint]
                                            AND a.[Department] = b.[Department]
                                            AND a.[EmployeeCode] = b.[EmployeeCode]
                                            AND a.[Gender] = b.[Gender]
                                            AND a.[Surname] = b.[Surname]
                             )
如何获得比较LINQ查询?我不能使用SQL查询,因为数据已经在数据集中,现在需要进一步修改

我已尝试过,但这不起作用:

        var query = from a in excelTable
                    where
                    (
                        from c in excelTable
                        group c by new
                        {
                            c.Paypoint,
                            c.EmployeeCode
                        } into g
                        where string.Compare(a.Paypoint, g.Key.Paypoint) == 0 && string.Compare(a.EmployeeCode, g.Key.Paypoint) == 0
                        select g.Key.Paypoint
                    )
                    select a;

您还可以选择仅包含必填字段的匿名对象。取决于您。

您对SQL查询最直接的操作是:

var query = 
    from a in excelTable
    let maxIssueDate = 
        (from b in excelTable
         where a.Paypoint == b.Paypoint &&
             a.Department == b.Department &&
             a.EmployeeCode == b.EmployeeCode &&
             a.Gender == b.Gender &&
             a.Surname == b.Surname
         select b.ItemsIssueDate).Max()
    where a.ItemsIssueDate == maxIssueDate
    select a;

不幸的是,这只返回一个项目,每个日期,如果有许多项目与同一日期,它不工作…谢谢,这是工作-任何方式使它更快。。。。在backgroundworker中运行查询大约需要6分钟。。。
var query = 
    from a in excelTable
    let maxIssueDate = 
        (from b in excelTable
         where a.Paypoint == b.Paypoint &&
             a.Department == b.Department &&
             a.EmployeeCode == b.EmployeeCode &&
             a.Gender == b.Gender &&
             a.Surname == b.Surname
         select b.ItemsIssueDate).Max()
    where a.ItemsIssueDate == maxIssueDate
    select a;