I am trying to select the max sys_id
from a table where the sys_id
column is a varchar
type. Some rows contain text, but I am only concerned with the numeric values.
I have tried the following bit of code, but they do not work -- LINQ to Entities does not seem to support this operation.
public string GetSysID()
{
using (var context = new DbEntities())
{
int i;
// var intQuery = context.myTable.Where(t => int.TryParse(t.sys_id, out i)).Max();
int intQuery = Convert.ToInt32(context.myTable.Where(p => IsNumber(p.sys_id)).Max(p => p.sys_id));
//return context.drawings.Max(p => p.sys_id);
return intQuery.ToString();
}
}
public static bool IsNumber(string value)
{
int n;
return int.TryParse(value, out n);
}
Is there a way to do this using LINQ to Entities?