Changed lines from the list of objects?

I have a form where

Table SelectedItems Table AvailableItems RecordID CheckBoxID CheckBoxID Description 1 1 1 'Tomatoes' 1 2 2 'Potatoes' 1 4 3 'Mangoes' 2 1 4 'Apples' 2 2 
  • Now I need to edit SelectedItems for RecordID 1
  • For this purpose I made a CheckBox list and filled it with AvaialbeItems
  • Then I looped and checked SelectedItems for RecordID 1
  • The user selects some new lines from the available list (along with the old ones, he can also deselect)

Now I want to update the selected records, the problem is that I want to know only the new records to insert.

Both tables are returned as lists of business objects <>. How to compare lists and extract only changed / new lines?

Please advise me. I am using webforms on VSS 2005.

0
source share
2 answers

When you select the record (s), can you update the business object and pollute them? I mean creating a class variable that will serve as a flag that you can check to see if it has been changed or new. Select new rows (or old ones), which, it seems to me, will trigger an event that you can use to modify the selected row business object.

Then, when you look at your lists, you just need to check the flag of the business object, which gives the change status / new.

+1
source

If the system is already on a working server and is working stably, please ignore my answer. If it is still in the planning / design / programming stage, I think that probably a small change in the database will make everything a lot easier.

  Table SelectedItems RecordID CheckBoxID IsSelected 1 1 true 1 2 true 1 3 false 1 4 true 

That is, for a specific RecordID and CheckBoxID, you do not need to query the table to find if there is a corresponding record (which means that it is selected). There is always such an entry with IsSelected status in the new design.

Meanwhile, this design is also very convenient for serving on your web pages. What you are changing is just the IsSelected value for a specific row, you do not need to worry about "Oh, do I need to delete one row or add it?" β€œIs the data in this row dirty or not?” ... things get simpler.

0
source

All Articles