LINQ到实体无法识别方法“的Int32的Int32(System.String)'在MVC C#方法 [英] LINQ to Entities does not recognize the method 'Int32 Int32(System.String)' method in MVC c#
本文介绍了LINQ到实体无法识别方法“的Int32的Int32(System.String)'在MVC C#方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我试图查询使用LINQ到实体我得到这个异常Databae语境。结果
LINQ到实体无法识别方法的Int32的Int32(System.String)的方法,而这种方法不能被翻译成店前pression。
请帮忙。
由于提前
如果(的Request.Form [登记]!= NULL)
{
字符串[] =选择的Request.Form [注册]斯普利特('')。 如果(选择!= NULL)
{
如果(selected.Count()!= 0)
{
INT K = 0;
的foreach(在选定的VAR项)
{
VAR ID = db.EnrollTrainee.Where(I => i.TraineeID == Convert.ToInt32(项目[K]的ToString())
&功放;&安培; i.TrainerID == Convert.ToInt32(会话[用户]的ToString()));
如果(ID!= NULL)
{
的foreach(在ID VAR一)//获取异常这里
{
enroll.id = a.id;
db.EnrollTrainee.Remove(登记);
db.SaveChanges();
}
}
ķ++;
}
}
}
解决方案
你有没有尝试过做转换你做LINQ之前?
所以像这样的:
的foreach(在选定的VAR项)
{
VAR tempId = Convert.ToInt32(项目[K]的ToString());
VAR tempId2 = Convert.ToInt32(会话[用户]的ToString());
变种的id = db.EnrollTrainee.Where(ⅰ= GT; i.TraineeID == tempId
&功放;&安培; i.TrainerID == tempId2);
如果(ID!= NULL)
{
的foreach(在ID VAR一)//获取异常这里
{
enroll.id = a.id;
db.EnrollTrainee.Remove(登记);
db.SaveChanges();
}
}
ķ++;
}
When I am trying to Query Databae Context using Linq to Entities I am getting this Exception.
LINQ to Entities does not recognize the method 'Int32 Int32(System.String)' method, and this method cannot be translated into a store expression.
Please help. Thanks in Advance
if (Request.Form["Enroll"] != null)
{
string[] selected = Request.Form["Enroll"].Split(',');
if (selected != null)
{
if (selected.Count() != 0)
{
int k = 0;
foreach (var item in selected)
{
var id = db.EnrollTrainee.Where(i => i.TraineeID == Convert.ToInt32(item[k].ToString())
&& i.TrainerID == Convert.ToInt32(Session["user"].ToString()));
if (id != null)
{
foreach (var a in id)//Getting Exception Here
{
enroll.id = a.id;
db.EnrollTrainee.Remove(enroll);
db.SaveChanges();
}
}
k++;
}
}
}
解决方案
Have you tried doing the conversion before you do the linq?
So like this:
foreach (var item in selected)
{
var tempId = Convert.ToInt32(item[k].ToString());
var tempId2 = Convert.ToInt32(Session["user"].ToString());
var id = db.EnrollTrainee.Where(i => i.TraineeID == tempId
&& i.TrainerID == tempId2);
if (id != null)
{
foreach (var a in id)//Getting Exception Here
{
enroll.id = a.id;
db.EnrollTrainee.Remove(enroll);
db.SaveChanges();
}
}
k++;
}
这篇关于LINQ到实体无法识别方法“的Int32的Int32(System.String)'在MVC C#方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文