无法使用enity框架将数据更新到数据库中 [英] Unable to update data into database using enity framework
本文介绍了无法使用enity框架将数据更新到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尊敬的先生
我正在尝试使用c#(实体框架)将数据更新到数据库中。我没有在代码中收到任何错误,而是记录成功更新消息出现。但是我没有在数据库表中找到任何变化。我正在努力两个小时,但没有任何积极的事情发生。
提前致谢
Respected sir
I am trying to update data into database using c# (entity framework).I am not getting any error in the code,instead record successfully updated message appears.But I don't find any changes in Database table.I am struggling for two hours,but nothing positive came up.
Thanks in advance
推荐答案
//For Saving and updating if you are using linq to entities
using (CustomerEntities customerDataContext= new CustomerEntities())
{
Customer customer = (from c in customerDataContext.Customers
where c.Name == "customer name"
selext c).First();
if(customer !=null)
{
c.Name = "New Customer Name";
}
customerDataContext.Customers.SaveChanges();
}
这篇关于无法使用enity框架将数据更新到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文