I need to retrieve the MAX(timestamp) value from a SQL table into a string variable but can't figure out how.
So if my table/entity is set up like so:
**DEPARTMENTS**
Department varchar(10) PK
LastUpdated timestamp
What would the Linq query look like? I have tried a few iterations but always get an error.
EDIT: Here is an example of what I tried
var result = (from d in _context.LOG_Departments
select d.LastUpdated).Max().SingleOrDefault();
error: "Cannot implicitly convert type 'byte' to 'string'
EDIT Solution:
public string MaxDepartment()
{
CPLinkEntities _context = new CPLinkEntities();
var results = _context.LOG_Departments.Max(t => t.LastUpdated);
string hex = BitConverter.ToString(results);
hex = hex.Replace("-", "");
return hex;
}
SingleOrDefault()?Max()already gives you single value