3

please help me What Should I do with this Error in this Code:

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

var bookImagePage = (from bbs in LibCms.Books
                             join bbp in LibCms.BookPages on bbs.BookID equals bbp.BookID
                             select new
                                        {
                                            bbs.BookID,
                                            bbp.VolumeNum,
                                            bbs.AutolID,
                                            bbp.PageNum,
                                            a = bbs.AutoID.PadLeft(5, '0') + bbp.PageNo.PadLeft(4, '0')
                                        }).Distinct().ToList();
user3559773
  • 41
  • 1
  • 3
  • Possible duplicate: [any of these](https://www.google.co.uk/search?q=LINQ+to+Entities+does+not+recognize+the+method). – Rawling Apr 22 '14 at 09:33
  • This should help: [Any workaround for lack of support for PadLeft in EF5.x?](http://stackoverflow.com/questions/15138234/any-workaround-for-lack-of-support-for-padleft-in-ef5-x) – Magnus Apr 22 '14 at 11:09

1 Answers1

4

You can't use methods in a Linq query. Take out the string manipulation then after ToList() add .Select(x=>new { //now you can use methods on the results })

Honorable Chow
  • 3,097
  • 3
  • 22
  • 22