entity-framework - Linq To Entities - 在 DB 上运行 CONVERT to int
问题描述
我在 DB 中的表包含 varchar 字段,其中包含字符串和整数值。要求是仅将整数与提供的值进行比较。这段代码
from c in Cars
where SqlFunctions.IsNumeric(c.Code)
&& Convert.ToInt32(c.Code) == 12
投掷
LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression.
在 LINQPad 中运行此查询运行良好!为什么?
问题:如何直接在数据库中转换字符串并与提供的整数值进行比较。
解决方案
为什么不只是:
from c in Cars
where c.Code == "12"
推荐阅读
- android - 当我在自定义 MotionLayout 中滚动时在 textview 中调整大小
- manjaro - 更新和重启后没有互联网 - Manjaro 5.4
- bash - 加密 Bash 文件夹中的每个项目
- graphdb - 在 GDB 存储库配置的导入参数中使用相对路径?
- apache-spark - 如何在火花中从字符串加载数据集
- ios - 如何找到瞳孔中心和眼镜框边缘之间的距离
- omnet++ - 致命错误:IPvXAddress.h:没有这样的文件或目录
- javascript - 通过html获得点击按钮
- c# - c# excel interop 点击按钮
- bash - 如果模式匹配,则仅列出命令输出的第一行