Getting maximum value from table using LINQ

Posted by Tena on Stack Overflow See other posts from Stack Overflow or by Tena
Published on 2012-06-15T16:39:34Z Indexed on 2012/06/16 3:16 UTC
Read the original article Hit count: 123

I have a table in my database. I want to get the maximum value of a column named NumOfView. I used this code:

var advert=(from ad in storedb.Ads where ad.AdScope == "1" select ad.NumOfView).Max();

It works but when there are two or more same maximum values it doesn't work and this message appears:

Sequence contains more than one element

What should I do now? Your answers will be very helpfull. Thanks

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about database