I am having problem with converting the DateTime I am collecting from the database to localtime with LINQ. A LINQ query won't let me use ToLocalTime() and I can't seem to get any fix outside the query to work with the anonymous type of list.
Here is the LINQ query from the controller :
// GET: api/Scan
public object Getv_Update_ComplianceStatusAll()
{
var dato = DateTime.Now.AddYears(-1);
var scan = (from n in db.C_RES_COLL_NO9000AC
join s in db.v_Update_ComplianceStatusAll on n.MachineID equals s.ResourceID
join u in db.v_UpdateInfo on s.CI_ID equals u.CI_ID
join c in db.v_CICategoryInfo on u.CI_ID equals c.CI_ID
where (n.MachineID == s.ResourceID) && (u.DateRevised > dato)
group s by new { n.Name } into grp
select new
{
Name = grp.Key.Name,
StatusScan = grp.Max(t=> t.LastStatusCheckTime)
});
return scan;
}
This is my attemt at a fix outside the query :
var newScan = scan.ToList();
foreach (var s in newScan)
{
s.StatusScan = s.StatusScan.ToLocalTime();
}
return newScan;
The converstion works, but it returns "Error 306 Property or indexer 'AnonymousType#1.StatusScan' cannot be assigned to -- it is read only"
So, how do I convert the UTC to local time in the controller (before I return anything to the website)?