C# Finding the maximum value of a string with linq

前端 未结 3 1172
你的背包
你的背包 2020-12-21 15:46

This is what I have and it keeps returning null.

It doesn\'t recognize the Convert.toInt32 when I add a where statement

var maxTopID = (from max in         


        
3条回答
  •  时光取名叫无心
    2020-12-21 16:19

    How about converting the TopicID in SELECT and use String.IsNullOrEmpty() to remove empty string, like:

     var maxTopID = (from max in dbcontext.Topics.Local
                     where !String.IsNullOrEmpty(max.TopicID)
                     select Convert.ToInt32(max.TopicID)).Max();
    

    See the Demo

提交回复
热议问题