0

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クエリをどのように取得しますか?データはすでにDataSetにあり、さらに変更する必要があるため、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;
4

2 に答える 2

2
var query = from a in MyTable
            group a by new { 
              a.Paypoint,
              a.Department,
              a.EmployeeCode,
              a.Gender, 
              a.Surname
            } into g
            select g.OrderByDescending(x => x.ItemsIssuedDate)
                  //.Select(x => new { required properties })
                    .First();      

必須フィールドのみの匿名オブジェクトを選択することもできます。君による。

于 2013-02-25T14:41:48.133 に答える
0

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;
于 2013-02-25T15:05:38.757 に答える