How to get max value of a column using Entity Framework?

后端 未结 10 2159
旧时难觅i
旧时难觅i 2020-12-13 05:16

To get maximum value of a column that contains integer, I can use the following T-SQL comand

SELECT MAX(expression )
FROM tables
WHERE predicates;

10条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 06:15

    Try this int maxAge = context.Persons.Max(p => p.Age);

    And make sure you have using System.Linq; at the top of your file

提交回复
热议问题