Reputation: 11001
For example
a = datacontext.customers.FirstOrDefaul();
b = datacontext.customers.Skip(1).FirstOrDefaul();
a.name="name1";
b.Name="name2";
When i call datacontext.SubmitChanges(), Two object updated. I don't want this.
I need only Update a
object. How do it?
EDIT
WPFWindow windowA=new WPFWINDOW()
windowA.DataContext=a;
windowA.Show();
WPFWindow windowB=new WPFWINDOW()
windowB.DataContext=b;
windowB.Show();
When clicking save button from window, corresponding object saving.
When clicking cancel button, corresponding object not saved
Upvotes: 0
Views: 277
Reputation: 25601
My understanding is that the purpose of a DataContext is to encapsulate a set of changes to be submitted together. If you want some changes to be separate, create another DataContext instance. DataContexts, I believe, are intended to be lightweight and quick to create and release. In the application I have created that uses LINQ to SQL heavily, I create a separate DataContext for every window. Do NOT use a shared data context for your whole application. It's not like a database connection. That's why the database connection is a separate object.
Upvotes: 0
Reputation: 12954
if you don't want to save changes to b, then why assign b.name = "name2". Use a temporary variable to store "name2". Later you can assign it to b.name if you want
Upvotes: 0