I'm working on an app in MVC4 and Entity Framework 5 and recently came across this exception when executing my query.
{"LINQ to Entities does not recognize the method 'System.String PadLeft(Int32, Char)' method, and this method cannot be translated into a store expression."}
When I have run across similar errors in the past, I've just made a variable outside the query and then used the variable in the LINQ statement. Unfortunately, in this case I'm manipulating the row results so I'm not sure how to go about that or if that is the best method. Any help would be appreciated. My query is below:
IQueryable<System.String> LEAPrograms = db.Datamart_Draft
.Where(where => where.snapshot_id == snapshot_id
&& !String.IsNullOrEmpty(where.entity_program))
.Select(sel => (sel.entity_program.PadLeft(PROGRAMLENGTH, '0'))).Distinct();
It's not too elegant but it does the job:
...
.Select(sel => SqlFunctions.Replicate
("0", PROGRAMLENGTH - sel.entity_program.Length)
+ sel.entity_program)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With