views:

231

answers:

5

In my 2nd ASP.NET MVC project I'm facing a very weird problem: when I call the SubmitChanges method of the DataContext class, nothing updates in the database. It's weird because everything works fine with my first project.

I'm using a remote database created in Sql Server Management Studio, I tried doing some queries there and in Visual Studio 2010 (where I have the connection to the database), they all work.

Where might the problem be hidden?

DBDataContext DB = new DBDataContext();
var myuser = DB.Users.Single(u => u.ID == id);
myuser.Age = 45;
DB.SubmitChanges();

SOLUTION

This is embarrassing :D Indeed I didn't have a primary key. Now it works!

Thanks to everybody!

A: 

Maybe there isn't anything to submit to the database? SubmitChanges() only will submit modified or new data, if you don't have either, then it will no have any persitent effect.

You may want to read ScottGu's series on Linq to understand a bit more about Linq, or could want to by a book like Linq in action.

eKek0
A: 

Is it possible that the entities you are modifying are not connected to the DataContext? This would prevent them from causing updates to your database.

Greg Roberts
I created the linq to sql class as described in the nerdinner tutorial... How can I check if they are connected?
Alex
A: 

Added some code.

Alex
A: 

I'd check your connection string. You might not be connecting to the database you think you're connecting to.

roufamatic
+2  A: 

Table , KEY :)::):)

Insert KEY in TABLE !!!!!

wotu
Oh my gosh! This is embarrassing :D Indeed I didn't have a primary key. Thank you!
Alex