Which method of canonical EntityFunctions for .ToString()

╄→尐↘猪︶ㄣ 提交于 2019-12-13 07:58:39

问题


I am using EF and if I use expression like:

JobLinkId = jobItem.joblinkid.ToString()

it throws error because it is C# function. Which method of EF canonical functions should I use for this?


回答1:


I'm guessing that you're trying to use ToString in Linq to Entities query. If so then its impossible to use it there. The only walkaround i know is to use ToList on query and then use Linq to Objects to get result with ToString.




回答2:


To something like this:

instead of JobItem.joblinkid.ToString() use only JobItem.joblinkid inside your query and do a select afterwards:

myQuery.ToArray().Select(x => x.joblinkid.ToString())

I hope you get it. In any case: int is better than string, just wait till you really need the string and convert then.



来源:https://stackoverflow.com/questions/7397176/which-method-of-canonical-entityfunctions-for-tostring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!