Updating linq to sql entities totally eu dating

But the experience is still not what I would call intuitive.Ok, so the following code is an aproximation of a very simple disconnected operation.If you pass just the entity the entity is attached only but the changes that might exist are invisible - only explicit changes you make after Attach will update. Now this makes some sense - you can basically tell LINQ to attach and then compare the object state against an existing instance and based on that update the change state.Ok, that works, but it requires a Time Stamp field for every table. So what I unsuccessfully tried in my previous post is code like the following: I load up a second instance from the context and use that as a comparison.

updating linq to sql entities-23

Entities that have not been serialized still maintain associations with deferred loaders that can cause unexpected results if the entity becomes tracked by a second data context.Because the instance already exists from the Single load (based on the PK I presume), the Attach() fails.The Attach tried to synch finds that there's already another object in the context with the same PK and it fails.Another oddity here: If you use the Attach(cust,cust2) if the table has a Time Stamp field, Submit Changes also fails with: I suspect that's a bug in the way Attach updates the entity from the 'original state' and is inadvertantly updating the Time Stamp field.This happens inside of the LINQ code - the Update never hits the SQL backend. It works - but if you ask me the process is about as clear as mud.

Leave a Reply