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

.net c# entity entity-framework

Question

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);
1
5
3/17/2011 2:00:24 AM

Accepted Answer

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

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

Popular Answer

First of all, SaveChanges(true) is an obsolete method so I wouldn't recommend using it. Have you tried just using SaveChanges() ? Like in db.SaveChanges()

The closest method to SaveChanges(boolean) is SaveChanges(SaveOptions) which Persists all updates to the data source with the specified SaveOptions.



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