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;

 

posted @ 2014-02-16 10:39  zyip  阅读(312)  评论(0编辑  收藏  举报