我正在尝试使用 linq 查询,当我尝试以某种方式转换高度值时,我在运行时遇到错误。
Error:
LINQ to Entities 无法识别方法“Int32”
ToInt32(System.String)'方法,并且该方法无法翻译
到存储表达式中。
有没有更好的方法来比较高度值?
case "HeightFrom":
photosquery = photosquery.Where(x => Convert.ToInt32(x.physical.BodyHeight.TrimEnd()) >= Convert.ToInt32(height));
break;
问题是您使用的 Linq 提供程序(可能来自 EF)不支持Convert.ToInt32
。解决此问题的一个快速方法是使用AsEnumerable
切换到 Linq to Objects 的扩展方法
photosquery = photosquery.AsEnumerale()
.Where(x => Convert.ToInt32(x.physical.BodyHeight.TrimEnd()) >= Convert.ToInt32(height));
Now if BodyHeight
是一个字符串,并且您正在保存一个整数,我强烈建议如果可以的话更改该列的类型。您的查询可以完全在服务器端执行:
int value=Convert.ToInt32(height);
photosquery = photosquery.Where(x => x.physical.BodyHeight >= value);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)