Nic*_*rca 2 c# linq linq-to-entities
我得到以下异常:LINQ to Entities无法识别方法'Int64 ToInt64(System.String)'方法,并且此方法无法转换为存储表达式.
我有long.Parse(ProjectID.ToString()),我看到建议是使用Convert.ToInt64,但我仍然得到相同的异常
string projID = ProjectFileID.ToString();
var d = (from f in context.FileInfo
where f.ID == Convert.ToInt64(projID)
select (f));
Run Code Online (Sandbox Code Playgroud)
dle*_*lev 13
只需在查询外进行转换,因此您可以将结果直接与类型变量进行比较long:
// TODO: Error handling
long projID = Convert.ToInt64(ProjectFileID.ToString());
var d = (from f in context.FileInfo
where f.ID == projID
select (f));
Run Code Online (Sandbox Code Playgroud)
此外,考虑到你打电话ToString()的ProjectFileID,你能也许只是投它,而不是,因为它肯定好像它是一个int沿着这些线路什么的.
| 归档时间: |
|
| 查看次数: |
7386 次 |
| 最近记录: |