Lambda expression select min and max at the same time

How do I convert this to a Lambda expression when there are two columns to select at the same time?

LINQ

var lq=(from a in tbl
          group a by 0 into b
          select new { intYear = b.Min(p => p.intYear), tintMonth = b.Max(p => p.tintMonth) }
    ).SingleOrDefault();

T-sql

SELECT MIN(intYear), MAX(tintMonth)
FROM tbl

Lamdba expression

tbl.Select(x => x.intYear).Min();  //Can't figure how to select if 2 columns
+4
source share
1 answer

If you intend to return a "string" rather than two values, you can group all the strings together, as in the first LINQ expression:

tbl.GroupBy(t => 1)
   .Select(g => new { intYear = g.Min(p => p.intYear), tintMonth = g.Max(p => p.tintMonth) })

, , LINQ-to-SQL. , , . , Min() Max(). -, foreach .

+5

Source: https://habr.com/ru/post/1548609/


All Articles