score:3

Accepted answer

Apparently the current NHibernate Linq provider cannot combine Max() and an inner Select in the Select clause. You may need to pull the Max out of the Query and apply it afterwards, e.g.

int maxCount = session.Query<Device>()
    .Select(d => d.DeviceSensors.Count)
    .ToList()
    .Max();

A simpler version without a sub select works:

int maxCount = session.Query<Device>()
    .Select(d => d.Name.Length)
    .Max();

Related Articles