There is a table in our database the stores year and month, each being a char. The existing Linq to Entity query looks like this:
from mc in repository.table.AsQueryable()
orderby mc.Year descending, mc.Month descending
select mc).FirstOrDefault()
The issue with this is that it is ordering by string and not int, leading to the incorrect row being returned from the query. I have tried to convert the year and month to int and datetime, both throwing an error saying:
"LINQ to Entities does not recognize the method 'System.DateTime ToDateTime(System.String)' method, and this method cannot be translated into a store expression."
(from mc in repository.table.AsQueryable()
orderby mc.Year descending, Convert.ToDateTime(mc.Month) descending
select mc).FirstOrDefault()
OR
"LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression."
(from mc in repository.table.AsQueryable()
orderby mc.Year descending, Convert.ToInt32(mc.Month) descending
select mc).FirstOrDefault();
As you can see, I cannot cast the month and year into INTs first because it is using the data from the table, not external data.
PS: I do not have the authority to change the tables to make the two columns INTs.
Anyone know how to approach this?