当 Convert.i 尝试 int.Parse() 、 SqlFunction 和 EdmFunction 时,我得到 LINQ to Entities Int32 ToInt32(System.String) 但问题仍然存在。
例外:
System.NotSupportedException: LINQ to Entities does not recognize the method 'Int32 ToInt32(System.String)' method, and this method cannot be translated into a store expression
Code:
try
{
ModelEntities me = new ModelEntities();
var query = from p in me.Products
join c in me.ProductCategories
on Convert.ToInt32(p.CategoryId) equals c.CategoryId
select new
{
p.ProductTitle,
c.CategoryName
};
rptProducts.DataSource = query;
rptProducts.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
您不能在 linq 查询中使用 Convert.ToInt32。 Linq 有自己的语法,不识别外部方法。
您必须将要查找的变量提取到 C# 中,进行转换,然后将其用作另一个查询中的变量。或者,如果您有权访问数据库,则可以将两个 CategoryID 都设置为整数。类似的字段应该具有相同的类型,这是有道理的。
希望有帮助!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)