I created a .MDF database in my WPF application.
I then generated LINQ-to-SQL classes and used LINQ get all the customers.
Then I run through them and change each of their last names.
However, when I call SubmitChanges, the database remains unchanged.
I thought that was the purpose of SubmitChanges(), to submit changes to the database?
What am I missing, how do I "submit changes" back to my database?
public Window1()
{
InitializeComponent();
Main2DataContext _db = new Main2DataContext();
var customers = from c in _db.Customers
select c;
foreach (var customer in customers)
{
customer.LastName = "CHANGED lastname"; //ListBox shows changes
}
_db.SubmitChanges(); //does NOT save to database (???)
}
I think I know what the problem is. Are you using a local .mdf file? If that's the case, check your bin/debug folder. I bet you have a database in there with the changes. I think you have an .mdf file in your project that is getting copied to the bin/debug folder everytime you build. Therefore the changes are getting saved to the copy, and you're not seeing it reflected in the copy that resides directly in your project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With