views:

40

answers:

1

I have a detached set of client objects that I'd like to update (I know they already exist in the db by primary key). Now I want to update them to the database. Knowing I need to query them first, I do so and now have to basically take the properties from the deattached objects and apply them to the attached objects. I finally call save changes. Is there a slick way to apply these properties from the detached collection to the attached one?

NOTE: The detached objects don't have the primary keys in them but I do have enough information to link with via a comparer class.

+1  A: 

You don't need to do what you're doing. You can just call the Attach method on your ObjectContext to tell it that you want to work with your detatched objects. Then just call SaveChanges to update the database with your changed objects.

David Pfeffer
First attach, then modify, then SaveChanges.
Craig Stuntz
So if I attached the objects (that don't have the primary key), how would it know to sync up the object? I have a comparer class that does this with Linq calls but I don't see how I can do that through Attach
RailRhoad
If the PK isn't set, how do you know which objects they represent so that you can do the manual sync?
David Pfeffer
I have a comparer class that can determine that. It's what I use to Except and Intersect these objects.
RailRhoad
You should update the question with that information. That changes things considerably.
David Pfeffer