开发者

How to get the max row number from a table by using linq

开发者 https://www.devze.com 2023-01-06 11:30 出处:网络
SELECT ISNULL(MAX(ColumnName) + 1, 1) AS ColumnName FROM TableName How to write this query in LINQ.Is there any way to convert sql to linq . i want a converter.
SELECT ISNULL(MAX(ColumnName) + 1, 1) AS ColumnName 
FROM TableName

How to write this query in LINQ.Is there any way to convert sql to linq . i want a converter.

Above query works well but i want the same output on linq .How to ?

I know how to select max

  var products = ((from p in db.TableName
                 开发者_高级运维           select p.ColumnName).Max());


This should do it:

return (myContext.MyTable.Max(t => (int?) t.MyColumn) ?? 0) + 1
0

精彩评论

暂无评论...
验证码 换一张
取 消