LINQ to SQL Classes question

J

Jordi Rico

Hi,

well I have a question about something I thought would be trivial but
it's driving me nuts.
In my app I have a list of objects (let's say users) that have been
loaded with a datacontext.
I can add users, list them, etc.
But if I want to edit an user, my problems begin. I pass an user
object to a form, with databound controls to its properties (name,
surname, password...).
Because they are bounded, when I make any change to any control, the
underlying object results changed at the time also.
It has two effects:
a) A list of users shown in other form (from which I select the user
to edit) shows every change I make in edit form.
b) I am unable to cancel editing, because although changes are not
saved to database, they are in memory.

Any help?

Thanks for any help
 
M

Manu

If you are using LINQ to SQL (which you probably are) and Visual Studio LINQ
To SQL Autogenerated Classes this is not possible out of the box.
To Support this type of functionality your object needs to implement
IEditable Interface. which is not implementd in the above case.
 
J

Jordi Rico

Yes, I've read about this... problem is that with IEditable I have to
create the methods myself, which can be something tedious for every
object (specially with those with many properties).
Also, it doesn't solve problem (a), in which every property being
modified is shown in an underlying list of users, and is really
annoying...
 
S

sqlguy

I went thru same problem. The fix is:

If linqitems.GetChangeSet.Updates.Count > 0 Then
linqitems.Refresh(RefreshMode.OverwriteCurrentValues,
linqitems.GetChangeSet.Updates)

where linqitems is your datacontext.

First check to see if there have been updates made to the memory objects
using GetChangtSet. Then if there are changes you want to revert back to the
original values the linqitems.refresh will do it.

Hope this helps
Lloyd Sheen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top