Order by a string within Select

Hey all,

We purchase the quote revisions module from Epicor when we went to E10. Works ok and as expected. I’m just trying to do some requested enhancements such as display the most recent revision that the sales person is working on. Simple I thought but the developers decided to make the RevisionNumber field nvarchar instead of int. I am trying to sort descending then get the FirstOrDefault but cannot figure it out the sort. Any help would be greatly appreciated. Here’s my latest attempt but I get no selected record.

CsgRevisionData = (from CsgRevisionData_Row in Db.CsgRevisionData
where CsgRevisionData_Row.Key1 == ttQuoteHedRow.QuoteNum.ToString()
orderby System.Convert.ToInt32(CsgRevisionData_Row.RevisionNum) descending
select CsgRevisionData_Row).FirstOrDefault();

Currently, the stored values on what I am working on are 0 through 19.
Thanks,
Chris

Try something like this

int CsgRevisionData = Db.CsgRevisionData.Where(c => c.Key1 == ttQuoteHedRow.QuoteNum.ToString()).Select(c => c.RevisionNum).Cast<Int32>().DefaultIfEmpty(0).Max();

Perfect! Thank you!