VS2008 - db.GetTable<T>().Attach(obj); error

Dec 7, 2007 at 12:35 PM
Hi,
I found a problem using the latest code and I don't know how to fix it.
Here's the message I get from VS2008 :
An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported.
The file is DatabaseHelper.cs (line 30 - db.GetTable<T>().Attach(obj);)

Any help ?
Stan
Dec 8, 2007 at 3:51 PM
Latest code updated that fixes the problem
Jan 19, 2008 at 7:41 AM
Edited Jan 19, 2008 at 7:47 AM
I've also found the same problem that stan92 reported. In fact, the production code (http://www.dropthings.com/) also suffers from the same problem (as of today, Jan 18). Just click a page tab and you will trigger the error. I am using the Dec 8 code for VS08 RTM (I've used source, not binary version). One observation is that error appears to be caused by LINQ from aspx; WF does not seem to cause the error. Not sure if page caching may be involved but since default.aspx disables caching, page caching is unlikely to be a culprit. I'll try to look for solutions and report back if there is any success. I am also trying to figure out if Omar's blog on "Linq to SQL: How to Attach object to a different data context" may offer a solution.
'
UPDATE: I didn't realize this issue was also reported in the Issue Tracker (item #4740 ).
Jan 25, 2008 at 12:37 AM
Same here. I'm running on the latest build as of this week. Is it possible that the version available on the site is not the build Omar is referring to?