C#Entitity框架调用SaveChanges()不工作 [英] C# Entitity framework SaveChanges() not working

查看:456
本文介绍了C#Entitity框架调用SaveChanges()不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行此code后,我发现我的数据库没有entrys。 我收到了code没有错误。

有谁知道我螨做错了?

  PeopleEntities1 DB =新PeopleEntities1();


            人罗杰=新的Person()
            {
                年龄= 25,
                名字=罗杰,
                姓氏=兔,
                位置=加拿大
                工作=自由职业者,


            };

            db.AddToPeople(罗杰);
            db.SaveChanges(真正的);
 

解决方案

什么是你的数据库的位置?请确保你没有你将它复制到你的输出目录每次你运行你的code。我可能已经与这是我每次运行我的应用程序时复制到输出目录中的SQLite数据库,这让我失去了我的previous运行期间所进行的更改类似的问题

After running this code I find no entrys in my database. I receive no errors from the code.

Does anyone know what I mite be doing wrong ?

PeopleEntities1 db = new PeopleEntities1();


            Person roger = new Person() 
            {  
                age = 25,
                firstname = "Roger", 
                lastname = "Rabbit", 
                location = "Canada", 
                job = "freelance", 


            };

            db.AddToPeople(roger);
            db.SaveChanges(true);

解决方案

What is the location of your database? Make sure you are not you're copying it to your output directory everytime you run your code. I might have had a similar issue with an SQLite database which was copied to the output directory every time I run my application, which made me lose changes I had made during the previous run

这篇关于C#Entitity框架调用SaveChanges()不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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