What could be causing db.SubmitChanges() to not work in linq-to-sql?

This can happen if you don't have a primary key defined on the tables in SQL Server.

This bit me once - I'd submit changes, never get an exception, and it would go on its merry way, but never actually make it into the DB. All because I didn't specify, in the table, what my primary key was. – Matt Oct 16 '09 at 16:45.

For some reason the context may not be tracking changes. Try wiring up your db. Log to a writer and inspect what LINQ->SQL is doing when you call SubmitChanges().. db.

Log = Console. Out; Then you can watch your output window running in debug and see what is going on.

There's an article about how this might cause you to get a copy of the file and not the original, causing the symptoms you're describing. FTA: I think the project system or server explorer wizard offers to 'copy' your mdf into your project directory. Maybe you are operating on a copy of the database and viewing the other in server explorer.

Just set the primary key on table. It will fix the problem.

Your changes are not transmitted to the server until you explicitly call SubmitChanges on the DataContext. When you make this call, the DataContext tries to translate your changes into equivalent SQL commands. You can use your own custom logic to override these actions, but the order of submission is orchestrated by a service of the DataContext known as the change processor.

When you call SubmitChanges, LINQ to SQL examines the set of known objects to determine whether new instances have been attached to them. If they have, these new instances are added to the set of tracked objects. All objects that have pending changes are ordered into a sequence of objects based on the dependencies between them.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions