score:4

Accepted answer

max is looking to return an int because that's the type of p.level, but forced to return a null (because there are no items in the query). if you cast p.level to a nullable int, your query should work.

var nextlevel = (from p in cd.objective
                 where p.parent_objectiveid == null
                 select (int?)p.level).max();

Related Query

More Query from same tag