With LINQ to SQL in a ASP.NET MVC website I can display objects (records) from my database table.
Now I would like to create a new object and save it back to the database.
In my Controller, I do this:
var dataContext = new MessageDataContext(); Message message = new Message(); message.Action = 'save'; message.Body = 'record'; message.Parameter = '234';
And now I want to SAVE it with something like this:
message.Save();
Or perhaps:
dataContext.SubmitChanges(message);
But neither of these work.
What is the syntax here to:
- add new objects and save them to the database?
- make changes on existing objects and save them to the database?
What you’re looking for is:
Assuming you have a
Messagestable mapped into your LINQ to SQL DBML.