|
ms
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
LINQ to SQL Classes questionwell 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 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. Show quoteHide quote "Jordi Rico" <jordir***@gmail.com> wrote in message news:8bcece01-9a6e-4b28-b799-733e314a11d4@r36g2000prf.googlegroups.com... > 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 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... Show quoteHide quote On 17 dic, 11:06, "Manu" <manu.is***@gmail.com> wrote: > 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. > > "Jordi Rico" <jordir***@gmail.com> wrote in message > > news:8bcece01-9a6e-4b28-b799-733e314a11d4@r36g2000prf.googlegroups.com... > > > 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 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 Show quoteHide quote "Jordi Rico" wrote: > 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... > > On 17 dic, 11:06, "Manu" <manu.is***@gmail.com> wrote: > > 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. > > > > "Jordi Rico" <jordir***@gmail.com> wrote in message > > > > news:8bcece01-9a6e-4b28-b799-733e314a11d4@r36g2000prf.googlegroups.com... > > > > > 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 > >
Other interesting topics
replacing characters in a string
How to Verify if EventHandler for ValueChanged has been set? Procedure xxx expects parameter '@ID' which was not supplied Linq Style Can C# 3.0 not be used in websites? Design of a suer interface similar to visual studio Cross Platform encryption/decryption Bogus control property values Repository and Services Import a form |
|||||||||||||||||||||||