Linq To Sql updates DataContext but not the databa

2019-09-11 13:09发布

问题:

I can't update the database but when im debuging it, production is updated and created records in context. But when I close the debugging, the database has no any Data Definition.

I enjoyed coding until I got stocked up with this 'not updating' SubmitChanges() method to the database(but updates the context). It really kills me, i'm stocked about few hours finding solution in the web.

By the way, I set 'id' as Production PK with Identity incremented in pk property. Also in .dbml file, I set also set auto increment. Below is my code:

 qmsDBDataContext context = new qmsDBDataContext();
 public void AddProduction(int quails, int eggs, int feeds, int id_box) {
        Production production = new Production();
        production.quails = quails;
        production.eggs = eggs;
        production.id_box = id_box;
        production.feeds = feeds;
        context.Productions.InsertOnSubmit(production);
        context.SubmitChanges();
}

回答1:

I found a fix exactly answers my problem it was explained here . The mdf file I was working on existed in my project/debug folder, and the mdf file that server explorer was looking at existed in the project folder. Thanks to Matt Warren - MSFT to answering this question. Cheers

@sgmoore Thanks for giving me ideas about Transaction Scope Thing.