只需将字符串保存到临时变量中,然后在表达式中使用它:
var strItem = item.Key.ToString();IQueryable<entity> pages = from p in context.pages where p.Serial == strItem select p;
出现问题是因为
ToString()未真正执行,而是将其转换为MethodGroup,然后将其解析并转换为SQL。由于没有
ToString()等效项,因此表达式失败。
注意:
确保您还检查了有关以后添加的帮助程序类的Alex的答案
SqlFunctions。在许多情况下,它可以消除对临时变量的需要。



