Linq To Sql updates DataContext but not the databa

2019-09-11 12:35发布

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条回答
男人必须洒脱
2楼-- · 2019-09-11 13:04

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.

查看更多
登录 后发表回答