有人可以帮忙吗?预先感谢 [英] Can anyone help? Thank in advance

查看:56
本文介绍了有人可以帮忙吗?预先感谢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行时会出现如下异常:





while running it gives exception like below:


LINQ to Entities does not recognize the method 'Int32 Parse(System.String)' method, and this method cannot be translated into a store expression.





我尝试过:





What I have tried:

demo db = (from c in ob.demoes
                       where c.id ==Convert.ToInt32(txtboxId)
                       select c).FirstOrDefault();
            db.name = txtboxName.Text;
            db.salary = int.Parse(txtboxSalary.Text);
            ob.SaveChanges();

推荐答案

首先尝试进行转换:

Try doing the conversion first:
int id = Convert.ToInt32(txtboxId);
demo db = (from c in ob.demoes
           where c.id == id
           select c).FirstOrDefault();
db.name = txtboxName.Text;
db.salary = int.Parse(txtboxSalary.Text);
ob.SaveChanges();



但它应该是不必要的。当然,它在普通Linq中工作正常:


But it should be unnecessary. Certainly, it works fine in normal Linq:

int id = 66;
string sid = "66";
List<MyClass> list = new List<MyClass>();
MyClass mc = new MyClass();
mc.id = 55;
list.Add(mc);
mc = new MyClass();
mc.id = 66;
list.Add(mc);
var x = (from c in list
        where c.id == id
        select c).FirstOrDefault();
var y = (from c in list
         where c.id == Convert.ToInt32(sid)
         select c).FirstOrDefault();



编译并运行正常,x和y都包含相同的实例。


Compiles and runs fine, and x and y both contain the same instance.


这篇关于有人可以帮忙吗?预先感谢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆