I am just learning Linq and ran into a problem. For some validation, I am getting the last odometer reading from our database and need to compare that to the next reading. The odometer reading is an int on the incoming data and double on the database (changed to int on the dbml file).
Below is my code:
private bool IsValidOdometer(string equipment, int odometerReading)
{
bool returnVariable = true;
CarteGraphDataDataContext db = new CarteGraphDataDataContext();
var odometer = (from p in db.EquipmentMainGenerals join q in db.EquipmentFuelLogs
on p.wdEquipmentMainGeneralOID equals q.wdEquipmentMainGeneralOID
where p.VehicleId == equipment
orderby q.Odometer descending
select q.Odometer).Take(1);
int previousOdometer = odometer;
if (odometer.Count() != 0)
{
if (odometerReading < previousOdometer)
{
returnVariable = false;
}
}
return returnVariable;
}
The problem line is int previousOdometer = odometer;
. The error I get is:
Cannot implicitly convert type 'System.Linq.IQueryable' to 'int'
How do I fix this?