Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Linq to Sql, does not update, but does not throw exception

Running .net 2008, asp.net, Linq to sql, sql server 2008 express

Foo f = db.Foo.First(x => x.ID == id);
f.IsValid = true;
db.SubmitChanges();

I have a very basic table, which has several fields, and no FK constraints. None of the data saves when I call .SubmitChanges(), but no error is thrown. Any ideas?

Not using any explicit transaction scope, fields are not autogenerated, and no triggers on the server.

like image 925
Russell Steen Avatar asked Apr 28 '26 09:04

Russell Steen


1 Answers

Tyop aside, the first thing to try is setting db.Log = Console.Out; to see if any TSQL is issues (or better: run a SQL trace). If nothing is getting sent then maybe IsValid was already true - it won't re-save such changes unless it has to (unless you force it).

Less likely, you could perhaps have accidentally turning off object-tracking (db.ObjectTrackingEnabled).

Other common mistakes include:

  • not calling Complete() when using TransactionScope (if you are using TransactionScope)
  • with database files (rather than a separate server), checking in the original file (in the solution) rather than in the build output (typically /bin/debug or /bin/release).

I'm also assuming that IsValid is actually a db-mapped property (they don't have to be)

like image 98
Marc Gravell Avatar answered Apr 29 '26 23:04

Marc Gravell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!