views:

137

answers:

1

I've got a Silverlight app using RIA services and LINQ2SQL and have objects in my Silverlight app.

I query all the records in a table (via a LINQ query, using a datacontext) in the Silverlight app and create a user control for each object (record) and put that object into the control because I need the information later. Then later, the user makes changes to that object (stored in the control) and I want to save it back to the database.

My problem is that when I go to save the object I have no datacontext to execute SubmitChanges against. I can't attach it to a new context because it says it's already attached.

What the best practice for this situation?

A: 

Create a new DataContext, use it to retrieve the record in question, make your changes to the record, and execute SubmitChanges().

Robert Harvey
So there's no way to use the record I've stored in the control? I need to get it again, copy the contents of the stored record into it and SubmitChanges() on that? Seems kinda redundant since I already have a record. The record I have is quite simple, so it would be easy in this case, but if I had a complex record (object) it would soon get pretty ugly to copy over.
Handleman
If you have a way to databind the record, you might get away with not having to copy all the values. Have a look here: http://www.aspfree.com/c/a/Windows-Scripting/Introducing-Two-Way-Data-Binding-using-Silverlight-20-WCF-and-LINQ-to-SQL/
Robert Harvey