-2

I am working on a WPF application using the MVVM pattern. Part of the UI is a lot like a master detail setup. The objects displayed are POCOs with a database for persistence.

My question is what should happen after an insert/update/delete - should the entire list be reloaded from the database with a GetList() and new POCOs be created, or is it enough to keep the existing list in memory and just add/update/delete the new POCO?

Rye bread
  • 1,305
  • 2
  • 13
  • 36
  • 1
    Getting an entire collection from DB each time the DB is updated, will be a little expensive, wouldn't it? – Alex May 22 '17 at 14:39
  • Are you using ORM? This is the ideal situation for something like that. Additionally, you can just populate an observable collection in your view models with an initial load and add/remove items to and from that (also execute INSERT and DELETE if you aren't using ORM); this will update your views dynamically provided the collection is bound properly. Here's an example: https://stackoverflow.com/questions/4279185/what-is-the-use-of-observablecollection-in-net – Matthew Alltop May 22 '17 at 14:43

1 Answers1

1

Well, it depends. If you are only updating the records in the database from the client application on your machine, it is not necessary to reload the data after you have performed an insert/update/delete as you will always have the latest changes in memory already anyway.

But if the database may be updated from somewhere else, you will need to fetch/reload the data at regular intervals in order to display the latest known data to the user.

Note that this has nothing to do with the MVVM design pattern though.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • MVVM controls usually bind to POCOs though. – Rye bread May 22 '17 at 15:01
  • What do you mean and what does this has to do with your question...? POCOs are nothing but in-memory objects. – mm8 May 22 '17 at 15:02
  • I have some issues where ComboBoxes are cleared when updating the source list, because the selected item references are no longer in the list. I want to make sure I fix those issues while following the pattern... – Rye bread May 23 '17 at 08:46
  • Again: This has nothing to do with your original question. Please ask a new question if you have another issue. – mm8 May 23 '17 at 09:28