You could always add Double.MinValue
to the sequence. This would ensure that there is at least one element and Max
would return it only if it is actually the minimum. To determine which option is more efficient (Concat
, FirstOrDefault
or Take(1)
), you should perform adequate benchmarking.
double x = context.MyTable
.Where(y => y.MyField == value)
.Select(y => y.MyCounter)
.Concat(new double[]{Double.MinValue})
.Max();