IDataServiceQueryable
doesn't support full set of LINQ operator like IEnumerable
has.
IDataServiceQueryable – This is a LightSwitch-specific type that allows a restricted set of “LINQ-like” operators that are remote-able to the middle-tier and ultimately issued to the database server. This interface is the core of the LightSwitch query programming model. IDataServiceQueryable has a member to execute the query, which returns results that are IEnumerable. [Reference]
Possible solution is, execute your query first to get collection of type IEnumerable
by calling .ToList()
, then you can call .Min()
against the first query result. But that isn't good idea if you have large amount of data, because .ToList()
will retrieve all data match the query and do further processing in client side, which is inefficient.
Another way is, change your query using only operators supported by IDataServiceQueryable
to avoid retrieving unnecessary data to client. For example, to get minimum StartNo
you can try to use orderby descending
then get the first data instead of using .Min()
operator :
var minStartNo =
(
from ts in this.DataWorkspace.SQLData.Timesheets
where ts.Job.ID == this.TimesheetProperty.Job.ID
orderby ts.StartNo descending select ts
).FirstOrDefault();