C#Entitity框架调用SaveChanges()不工作框架、工作、Entitity、SaveChanges

2023-09-05 23:15:24 作者:感受

运行此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.

entity framework无法写入数据库.SaveChanges 失败

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