Update Entity through a new Object in LINQ to SQL?

The Attach() is not working because the entity is still attached to the DataContext. Have you considered creating a new instance of your DataContext for when you reattach your entity? It is generally recommended not to have long-lived DataContexts, instead you should create a new instance per unit of work.

This is because as long as you keep a DataContext instance in memory, all of the entities you have retrieved from it remain in memory as well (assuming ObjectTracking is enabled) From MSDN: In general, a DataContext instance is designed to last for one "unit of work" however your application defines that term. A DataContext is lightweight and is not expensive to create. A typical LINQ to SQL application creates DataContext instances at method scope or as a member of short-lived classes that represent a logical set of related database operations http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.aspx.

The Attach() is not working because the entity is still attached to the DataContext. Have you considered creating a new instance of your DataContext for when you reattach your entity? It is generally recommended not to have long-lived DataContexts, instead you should create a new instance per unit of work.

This is because as long as you keep a DataContext instance in memory, all of the entities you have retrieved from it remain in memory as well (assuming ObjectTracking is enabled). From MSDN: In general, a DataContext instance is designed to last for one "unit of work" however your application defines that term. A DataContext is lightweight and is not expensive to create.

A typical LINQ to SQL application creates DataContext instances at method scope or as a member of short-lived classes that represent a logical set of related database operations. http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.aspx.

I used recursion after all, but your answer is sound :-) thanks – Dänu Jun 5 '10 at 14:40.

I'd like to update an entity via linq, but since I edit the entity in a view after serializing it, I don't have direct access to the entity inside the data context. Thats not cool... not cool at all. Doesn't work either.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions