SaveChanges() in the C# Entity Framework does not function.

.net c# entity entity-framework

Question

My database has no entries after executing this code, unfortunately. The code generates no errors for me.

Can somebody tell me what I could be doing incorrectly?

PeopleEntities1 db = new PeopleEntities1();


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


            };

            db.AddToPeople(roger);
            db.SaveChanges(true);
1
5
3/17/2011 2:00:24 AM

Accepted Answer

Where is your database located? Check to see if you are not transferring it to your output directory each time your code runs. An SQLite database that was moved to the output directory each time my program was run may have caused a similar problem for me, causing me to lose changes I had made during the previous run.

4
3/17/2011 3:59:11 AM

Popular Answer

To start with,SaveChanges(true) is an outdated technique, therefore I wouldn't advise utilizing it. Have you ever just usedSaveChanges() ? As indb.SaveChanges()

The most direct approachSaveChanges(boolean) is SaveChanges(SaveOptions) This keeps all data source changes with the givenSaveOptions .



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow