这是我试图修复问题的代码,但它提供了以下消息: LINQ to Entities无法识别方法'Int32 ToInt32(System.String)'方法,并且此方法无法转换为商店表达式。
string a = Request.QueryString["reqid"].ToString();
MasterPackEntities obj = new MasterPackEntities();
var ds = obj.news.Where(x => x.id == Convert.ToInt32(a)).ToList();
答案 0 :(得分:3)
执行查询的转换 ,因为查询提供程序无法理解转换:
//consider using `TryParse` to handle invalid input
int a = int.Parse(Request.QueryString["reqid"].ToString());
MasterPackEntities obj = new MasterPackEntities();
var ds = obj.news.Where(x => x.id == a).ToList();
答案 1 :(得分:0)
您收到此错误是因为LINQ to Entities
尝试将Convert.ToInt32
转换为SQL语句,但该语句失败。你可以这样做:
int a = Convert.ToInt32(Request.QueryString["reqid"].ToString());
MasterPackEntities obj = new MasterPackEntities();
var ds = obj.news.Where(x => x.id == a).ToList();