未将LINQ转换为Convert.Int64实体 [英] Convert.Int64 Is Not Reconized LINQ To Entities
问题描述
我收到以下异常:LINQ to Entities无法识别方法'Int64 ToInt64(System.String)'方法,并且该方法无法转换为商店表达式.
I am getting the following exception: LINQ to Entities does not recognize the method 'Int64 ToInt64(System.String)' method, and this method cannot be translated into a store expression.
我有long.Parse(ProjectID.ToString()),我发现建议使用Convert.ToInt64,但是我仍然遇到相同的异常
I had long.Parse(ProjectID.ToString()) and I see the suggestion was to use Convert.ToInt64 but I am still getting the same exception
string projID = ProjectFileID.ToString();
var d = (from f in context.FileInfo
where f.ID == Convert.ToInt64(projID)
select (f));
推荐答案
只需在查询之外进行转换,因此您可以直接将结果与 long
类型的变量进行比较:
Just do the conversion outside the query, so you compare the results directly to a variable of type long
:
// TODO: Error handling
long projID = Convert.ToInt64(ProjectFileID.ToString());
var d = (from f in context.FileInfo
where f.ID == projID
select (f));
此外,假设您要在 ProjectFileID
上调用 ToString()
,您是否可以将其强制转换,因为它似乎是一个 int
或类似的内容.
Also, given that you're calling ToString()
on ProjectFileID
, can you maybe just cast it instead, since it certainly seems like it's an int
or something along those lines.
这篇关于未将LINQ转换为Convert.Int64实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!