linq query, using int.parse to convert varchar to int while orderby

var t = from x in context.NewsLetterItem.ToList() //add .ToList at this place
                            where x.APPId == appid &&
                                allowedAddress.Contains(x.mailFrom)
                            orderby int.Parse(x.mailId) descending
                            select x;

else, if you use the following query,  an erro with following message would be thrown:

LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression.

var t = from x in context.NewsLetterItem
                            where x.APPId == appid &&
                                allowedAddress.Contains(x.mailFrom)
                            orderby int.Parse(x.mailId) descending
                            select x;
原文地址:https://www.cnblogs.com/zyip/p/3551156.html