Linq doesn't update modified property of class
First of all, I have read similar posts and cannot see how they solve this problem. If I am missing something about them, please indicate that.
My Linq code is very similar to Scott Gu's expensive product example. ... However, in my case, the database is not updated with the new value. There are no exceptions and all the variables seem to have reasonable values ββin the debugger (result set full, connection string correct, ...).
using (MyDataContext db =
new MyDataContext(CONNECTION_STRING))
{
var resultSet = from l in db.Logs
where l.ProcessCode == null
select l;
foreach (var bm in resultSet)
{
bm.ProcessCode = 1;
// Debugger shows bm.ProcessCode properly set
}
db.SubmitChanges();
}
Why is SubmitChanges () not updating the database?
NOTE. This is a simplified case of my actual method. Real also inserts records into another table. This insert works, so I'm pretty sure the connection string is correct and functional.
source to share
EDIT: See the answer to this question . This might be for you too. The answer turned out to be that LINQ to SQL will not perform updates if the table does not have a primary key. I bet you also need to establish primary key parts ColumnAttribute
in the classroom. Since you used the code generator, you may need to restore this part after updating the table in the database. Assuming this is a problem, of course.
Does the class match with the property ProcessCode
INotifyPropertyChanged
? And the property ProcessCode
fires the event PropertyChanged
?
You also need to make sure that the property DataContext
is set ObjectTrackingEnabled
to true. It should be the default, but it's easy to check.
You can also use the GetChangeSet
on method DataContext
to find out what updates are. This can help with debugging.
source to share
My first guess is that your Linq query is doing a deep copy in the resultSet of any matching elements. This way, when you do your db.SubmitChanges (), you are working with a different copy of the data. If you put a breakpoint right before db.SubmitChanges (), can you see that the data in the db is updated correctly?
source to share